This problem seems to come up a lot, and I think it comes for a large part from what stuffe mentioned in his answer. People put religion on a special pedestal, like it's a more important/valid/respectable/believable thing than any other opinion people hold. This causes the situation to be approached very differently from most other discussions, because both sides often buy strongly into the idea that you can't tell a religious person they are wrong because that's rude and religion is special/important.
Once you take that pedestal away, it becomes a different story, and suddenly talking about religion is more like talking about opposing political views. Also a discussion where people can get angry and loud, but at least one where saying the other person is wrong is somewhat acceptable.
Then, next is the idea that there is such an idea as "the true path", which is still pretty common with politics, where many people will refuse to accept that they might be wrong or that "the other" might have a good point. If you can take that away, suddenly talking about religion or politics turns into something closer to discussion favorite flavor of ice-cream. Without elevated importance or one-true-way-ism, a discussion about beliefs becomes just that: a discussion about what you believe. We never hear people asking "How to explain my child that I prefer chocolate, even though most people around him prefer vanilla" precisely because we accept that it's just a personal thing. And we would very quickly disassociate with people who keep hammering on how it's a sin to eat chocolate ice-cream. (The very idea sounds ridiculous, does it not?)
So... to go into the actual answer, I have below The 4 Rules you should teach your child to teach it to deal with this situation. (And many others)
Rule 1: There are no pedestals
There are only opinions and personal convictions. One's belief in gods is not more respectable than another's belief in alien visitations. Treat all of them the same way. People have a right to their opinions, and it's a basic virtue to not be an ass to people by crapping on their beliefs, but that should be extended to all beliefs equally.
For the most part, this will come down to pulling a few things down from their established pedestals so that they can be discussed for what they are: opinions.
When someone shares their belief with you, accept their opinions, say "that's nice", and maybe share your own. If they respond to your opinion with something that gives you the idea they treat your beliefs as less than their own (whether it is because you follow a different religion, no religion at all, or because you like a different football club or whatever) simply point out that both are just opinions and that you will refuse to discuss the topic unless both opinions are on equal footing.
(This will probably end most religious discussions, which is a good thing: there is nothing useful to be had from discussing religion with someone who believes their religion is more valuable than a dissenting opinion.)
Once you can really accept that there are no pedestals (and this is not as easy at it sounds; you will struggle with this, I still do) then you can discuss anything like a rational human being and you can cut short any pointless discussion with someone who put their opinion on a pedestal.
Rule 2: Accept that people can be wrong
Because a lot of them simply are. Topic does not matter; you will bump into people who are wrong all the time. This is something you will need to learn to deal with. We are often taught, sometimes openly and sometimes less so, that people with authority are correct, but this is simply nonsense.
This means that you will have to teach your child that you, the parent, might be wrong. His teacher might be wrong. The local pastor might be wrong. The policemen might be wrong. The president might be wrong.
That also means that when grandma says you are going to hell, you will fairly quickly start thinking "she just thinks that, she is probably wrong". It gives you a pretty good defense against strongly worded (unfounded) opinions.
So what you need to do when people tell you things, is think for yourself about whether they are correct. Think about why they think that, what they have to back their opinion up with, etc.
When you get into a religious discussion and someone says "God is against it", feel free to think they might be wrong and ask them "Why do you think that?" If they say "Just because", that means you can store it under "their opinion" with the backing arguments of "none at all", and it will hold no value to you.
If they complain that they should not have to back it up, because it is their religion, remind them about rule 1: everything is just opinion; there are no pedestals. An unfounded argument about religion is just as worthless as an unfounded argument on any other topic.
Rule 3: Accept that you can be wrong (and probably are)
This one is even harder, and even more critical. There is a near unlimited amount of information in the world and you don't know much of it. So realize that a lot of things you believe, especially those you have for a long time, might be wrong.
Be willing to hear people out. Accept that maybe your opinion of them, or of their opinion, or their religion, was unfounded. If you have believed something since you were 6, there is a good chance that opinion needs some updating. (After all, you probably believed in Santa too, back then)
This one is very important to teach children, because it will prevent them from brain-lock. That is a very common condition among adults, where once they believe something, they will never stop believing that thing because they refuse to accept that they could be wrong. It is how indoctrination works, and it's the last thing you would want to do to a child.
It also means you will never stop learning and will approach all situations with the idea that you could improve from them. Even religious discussions.
(And yes, it also means you will remain critical regarding these rules, which is a good thing! After all, I might also be wrong.)
Rule 4: Many people will refuse to accept these rules
A lot of people will adamantly refuse to admit they might be wrong about their religion, or will absolutely not accept their religion is just their opinion. You will need to learn to deal with these people (which is the crux of your question, I think).
Fortunately, the other 3 rules gives you plenty to work with. Ultimately, it is not within your power to change the opinion of a person who doesn't want their opinion changes, but then that is not the goal either.
You only need to accept that they are wrong, they keep their opinion on a pedestal and they don't want to have their mind changed: that means the only thing left to do is cut off any discussion from happening. Respectfully, if you can manage, or more strongly if you must.
The goal is to raise your child to think critically, challenge everything, not accept easily, be willing to discuss anything and revise opinions based on that. Once you do that, you can drop your child in any community and they will have the tools to deal with differences in opinion without being swayed by unfounded opinion.