Here's an older thread discussing possible theories explaining his special powers and his origin:
http://forum.barrowdowns.com/showthread.php?t=13380
The best explanation that I could find is that Beorn's ancestors (known to be related to the Woodmen and the Northmen) lived in the mountains and were forced to flee by the goblins. Perhaps they had a special relationship to bears, but I do not believe that they possessed any shapeshifting abilities at that time.
I believe that Beorn was the first to gain this ability and that he learned it from Radagast. We know that Radagast was a master of shapes and hues and since he loved being around his animal companions, perhaps he did so in animal form. After getting to know Beorn and realising that he loves nature just as much Radagast perhaps taught him how to shapeshift and gave him the possibility to defend himself and the animals against goblins.