I think this is an opportunity to clarify what Marx meant with this, because the social perception on opium has changed since his times. Opium during Marx time was used in Europe to treat pain, as a potent analgesic. For instance, Marx himself was prescribed opium to treat his painful skin blisters and carbuncles which had no treatment at his time. The perception of opium has changed since the Opium Wars in China, where a large part of the population was addicted to it.
When Marx said religion was the opium of the masses, he meant not that religion made them lethargic and passive, but that it treated the symptoms, not the condition itself.
As far as I interpreted it, Marx criticizes religion as the illusory happiness of the people, but he is also criticizing the philosophers at his time for focusing on the criticism of religion, that is on the opium, instead of criticizing the worldly matters, that is the condition.
It is, therefore, the task of history, once the other-world of truth has vanished, to establish the truth of this world. It is the immediate task of philosophy, which is in the service of history, to unmask self-estrangement in its unholy forms once the holy form of human self-estrangement has been unmasked. Thus, the criticism of Heaven turns into the criticism of Earth, the criticism of religion into the criticism of law, and the criticism of theology into the criticism of politics.