The best time of year to visit Naples would have to be between March - May or September and October.  During these months it is not quite cold or hot anymore, and the temperature sits around 20-25C (70-85 degrees farenheit).

The reason for this is that Italy sits in the middle of the Mediterranean Sea, which is far enough south that it can get quite hot during the spring and summer months.  Anytime you visit the south of Italy it is going to be fairly warm, except for the winter months when it can get relatively cool and wet. 

Spring and Fall can offer very comfortable temperatures, especially if you will be doing a lot of traveling in the countryside and doing outdoors activities like touring Pompei.  You can still visit late into the summer, but by then the heat can be quite overwhelming.

If you are going in the winter, remember that the week of Christmas is a very busy week, and many tourists will be in Italy because they will be visiting the Vatican.  Easter is also an important time for Italians because of the religious festivities. 

August is not the best time to visit Italy.  Besides being incredbly HOT, most of the country is on holiday.  August 15 (Ferragosto) is a day when the whole country closes for the day (except hospitals, airports, and hotels).  Italians spend the month of August on the beach relaxing.  So if you plan on being at the beach it is very busy.  Most tourist locations still have their stores and businesses open, and Naples is quieter than normal.  With most of the people of Naples being away on their vacation, the city is practically empty.  Naples is not as busy and chaotic with tourists as Rome or Venice.  So going to Naples during the summer will be hot, but you would not have to worry about crowds.