When Karl Marx described religion as the "opiate of the masses," he was being far more sympathetic to religion than most realize. Marx didn't object to using opiates to relieve the pain of injury, he objected to relying solely on opiates in place of fixing the injury. According to Marx, religion blinds us to problems in society by giving us something pleasing to focus on. More negative and less sympathetic interpretations of this idea can still offer legitimate insight on religion, though.
For example, while using pain killers to deal with a physical injury makes sense, using an opiate to deal with emotional, psychological, or social problems doesn't typically make a lot of sense — but that's precisely what a lot of people are doing when they abuse addictive drugs. Religion is arguably closer to this latter form of drug use than it is to the former because the problems in society which religion masks have a lot to do with our emotional and psychological relationships.
Religion is also often "sold" by apologists for just such uses: they proclaim that if you are experiencing psychological or emotional difficulties, then what you really need to do is accept their "faith" in God. It's also common for Christian apologists to make a big deal about how Jesus is offering us a "free gift" of salvation, but if you look at the package more closely you'll find that "free" isn't really so "free" after all. You may not need to pay money, but you are expected to believe what Christian authorities tell you about how you must behave, what you are allowed to believe, how you should vote, and so forth. Drug dealers' offer of a "free" first sample doesn't end up being so free, either.
When a drug is physically addictive, it creates a craving that only the drug itself can best relieve, thus providing both a problem and its own cure. Religions often do something very similar by first proclaiming that we all have some sort of "problem" which only that religion can cure; once part of the religion, though, you may find that the religion's rules ensure that you never actually stop experiencing that problem, thus ensuring that you always need that religion — and thus also ensuring the continued power of religious authority figures, institutions, and traditions. This means that adherents keep paying and paying and paying all their lives while the dealers at the top reap all the rewards.