Any time. Essaouira has a moderate climate with mild winters and warm dry summers. Averages highs range from 63F in January to 70F in August. See monthly weather averages for Essaouira.
Winter (Oct-Mar) is the best time for surfing - there is a chance of rain but also a fairly constant swell (summer can have flat spells). Summer (May-Sep) is best for windsurfing and kitesurfing.
Go in late June for the Essaouira Gnaoua and World Music Festival - a lively week-long event with performances ranging from traditional slave-derived music to contemporary jazz.