It's a point of some contention with major issues surrounding sourcing. The hadith mention Muhammad spending time in his youth with a man who taught him about the bible in Arabic. There's contention over this because many historians don't believe the bible would have been translated into Arabic at this point.
Nonetheless we can speak with greater accuracy about his general background which is to say that as a merchant living in a city that was both a mercantile center and a site of pilgrimage that Muhammad would have been exposed to good deal of diversity of faith, predominantly polytheists, but also large numbers of Christians and Jews.
What interaction he'd have had with specific religions is a point of contention, but in regards to your question unfortunately most of the evidence comes from within the development of Islam itself. Patricia Crone and Michael Cook wrote a book in the 1970s called Hagarism which purports that early Islam was basically a form of Judaism, although the authors themselves have moved away from this idea and it's been the subject of enormous criticism. Richard Bell, in an earlier generation believed that the earlier revelations of the Quran were not aimed at producing a new religion but were basically sermons intended to proselytize monotheism, probably Christianity. That's probably a more mainstream view.
Muhammad was born in Mecca, a town that was important because it was the site of the Ka'bah. The Ka'bah was the temple where many Arab tribes came to worship and pay homage to the pantheon of gods and goddess that ruled over Arabia, such as Al-Uzza, Al-Lat and Menat (who are all mentioned in the Qu'ran).
Muhammad had close family members who were priests and guardians of the Kab'ah, such as his uncle Abū Lahab. I think it's safe to say that Muhammad was presumed to be a member of the Kab'ah cult, although he never seemed to show any particular enthusiasm for paganism and indeed did spend time investigating minority religious traditions, such as the Hanifs.
Similar to what /u/cptbuck said, I'd like to add that Islamic sources also mention that he used to go alone to the mountains and meditate. Wondering about the creation of the universe and about God. He also has never joined his tribe in worshipping idols.