What you have to understand about Marx is that when he was writing, religion functioned in a very different way. In most contemporary Western cultures, religion is not all-encompassing. If you're asked to describe yourself, your religion isn't necessarily the first thing to comes to mind.
However, in the 19th century, when Marx was writing, religion played a much larger role in peoples' lives. Religions bound people together and tore people apart in 19th century Europe. In the UK, for example, some were poor and some were rich, but everyone was an Anglican, which gave people a sense of unity. Meanwhile, over in Ireland, everyone was a Catholic, which to many Brits gave them a good reason to rule Ireland. Now, to a contemporary viewer, these might have just seemed to be the effects of nationalism, but Marx didn't see it that way.
To Marx, history and everything in history was all about who held power, and to him, religion was just another way that the Bourgeoisie could oppress the Proletariat. For instance, when Marx saw all people of all classes participating in a common religion, he viewed it as a trick by the rich to pacify the working class with false promises of a better life after death. In this way, religion reinforced the status quo by fooling the poor into doing whatever the rich wanted.
Meanwhile, Marx also saw religion as an imperialist force. I mentioned earlier that European powers often used their religion as an excuse to colonize foreign lands. Well Marx saw this as another move by the rich to gain more economic resources to increase profits. Meanwhile, the colonies would suffer increasing poverty under the rule of European powers and the Bourgeoisie would get ever richer.
So, in short, Marx saw religion as a tool used by the rich to take advantage of the poor by fooling them into thinking that the afterlife would make up for their mortal suffering. Meanwhile, he also believed that the elite used religion as an excuse to colonize and exploit foreign nations for personal benefit. And therefore, he thought that the only solution to religions exploitative nature was to abolish it entirely and start an atheistic communist society.
TL;DR: Opium of the masses, excuse for imperialism.
I would like to add to the larger response that Marx was taught by Bruno Bauer, [I believe] the first scholar to challenge the veracity of Jesus as a historical figure.