It's widely held - almost axiomatic - that regardless of its truth or falsity, religion has a good effect of society. It teaches, say its proponents, morality, good behaviour, respect for authority and various other useful rules for living that benefit both its adherents and the populace as a whole.
Oops! - no it doesn't. Have a look at this research, in the Journal of Religion and Society.
Having dispensed with that aspect, let's talk about what other reason there may be for religion's existence.