You add religion to add depth, add character, add something for your characters to do. You can use religion to manifest your character's belief and bring them to life. Religion can be used as a sub-plot or simply an additional element. There are thousands of ways religion can help you, but there are just as many ways it can hurt you as well.
First off, you have to pick a reasonable stance. There are two religions in your book; the Pi and the Rock, one believes in reason and the other spirituality, and they hate each other. I get it if the character is a Rock and he hates the Pi with all of his heart, but you have to be careful. What if some little Pi girl out there reads your book? What then? Is she going to cry because of all the insults you threw at her people? Make sure, if you take that stance, there is some sort of forgiveness at the end, or be prepared to take the consequences.
Secondly, make it realistic, as with anything. Make me believe that this is a religion and that your character believes in it, otherwise it just becomes a nuisance.
Thirdly, keep it simple. You don't want to spend the entire book focused on the religion and loose the plot. The reader doesn't need to know everything about the religion, only the parts that affect the character directly.
Good vs. Bad. You can have your MC believe in the religion or have him set himself against it. You can have a religion be the bad guy/girl's thing and have your MC religion-less. There are thousands of ways that a religion can be added. Pick yours and be creative.
Don't feel that you need a religion! Some of the best stories have nothing about religion in them. And on the other hand, sometimes it's good to have your character lead by something greater than themselves.
Sorry for the short post, I don't have time to write much of a long one I think I covered the basic parts about religion in stories. If you have any questions, feel free to ask me. Have a nice day and good luck with your writing!
What is an instance where you have used religion? Did you use one from Earth or do your people have their own? Tell us about it.