Timetables are here. (Click the links under 'Ibiza Ferry Timetables'. You have to travel from Palma. There's no direct service from Magaluf):
http://www.aferry.to/ibiza-ferry-ferries.htm
It looks as if you'd have to spend the day on Ibiza. There's no convenient ferry just for a night out. The only suitable return ferry appears to be the Balearia service, at 0115.
Unfortunately, those timetables don't show the journey durations. Other websites indicate that typical journey times are around 2 to 2� hours. However, those are on the fast catamaran services. Conventional ferries will take longer. A website (which still has last year's timetables on it) states that the 0115 service ex Ibiza doesn't arrive until 0515. By the time you'd got a taxi back to Magaluf, you wouldn't get much sleep!
I can't find any fares with Balearia, but it's unlikely to be cheap. I found a fare for their rival company (which doesn't have convenient sailings for you) of �61 per person.
Chris