Get the supertours coach that leaves from Essaouira at 9.30am, this means you will be back in Marrakech by 12.30pm and you will have enough time to get to the airport in a relaxed manner, you will have time to look around Marrakech for 4-5 hours.
Make sure you book your return tickets as soon as you arrive in Essaouira, if the ticket office is closed, then get the return tickets as soon as possible (preferably the next morning). Also make sure you arrive for your coach with plenty of time to spare, if you arrive very close to departure, they may well sell your coach seat onto someone else (even if you have booked the seat).
There is another coach that leaves Essaouira at 11.45am, you could even catch that one but I would advise against it.........
I had a 7pm flight from Marrakech, wanted to catch the 9.45am coach but I did not get my ticket (got a bit too relaxed in Essaouira), anyway when I went to the ticket station at 9.15am the coach was full and there were already people on the waiting list, suffice to say I did not get on that coach and had to catch the 11.45am one, got back to Marrakech with plenty of time to spare but it was nice that I had the backup of the later coach.
I think the next coach after the 11.45am is at 3.15pm, that would be too late for you.
Once you are back in Marrakech coach station, the airport is a 15-20 minute drive away, get a taxi, it should cost no more than 50DH. If you have 4-5 hours to look around, consider hiring a driver (with a 7 seater type minibus) for a half day, it should cost you around £40 and you will have somewhere to store you luggage, the driver will pick you up at the coach station, take you around Marrakech and then take you to the airport, it will be a nice way to get some last minute shopping done and a final visit to Jemma el Fna square.
Edited: 11:02 am, April 20, 2013