If you are planning a trip to Visby the best time for the beaches and partying is definitely in the summer.  Gotland gets busier and more expensive during this time but there are tons more to do and see.  Watch out for the annual Medieval Week which takes place every year in the second week of August, the ferries are ususally completely fully booked for weeks, sometimes months ahead, and a lot of the locals flee Visby at this time to the countryside as it gets so busy.  The best time if you want a more quiet holiday would be spring or autumn (or  at the beginning or end of tourist season) as it's not as busy, the downside is that a lot of businesses (including hotels and restaurants) are closed at this time; a lot of businesses are only open during May - September. 

The weather is largely fine in the summer with long, light days and mild nights (although bring a jumper & raingear just in case).  July and August are the hottest months and the water usually heats up too, allowing for swimming in the Baltic Sea and sunbathing  on one of the many beaches around Gotland. However, be warned, the summers are not guaranteed to be warm and sunny, there can be spells of rainy, windy and cooler weather.  The winter is generally cold and snowy and windy from November to March.