Daniel, the ferries do not run after dark so whatever time the schedule shows for the last boat, is the last boat; no other options. It's possible that there might be one additional evening boat during high summer but I wouldn't count on it.
I don't think you can realistically do the grotto + get up to Anacapri for the chairlift up/hike down in 4-5 hours, especially during very busy high season. Honestly, if intent of seeing some of the island, I'd skip the grotto altogether as THAT is going to be your time eater. In my humble opinion, if there's a tourist trap on Capri, that's the one; too much time, $ and effort expended for the few minutes you're in the thing...if the seas cooperate enough to GET in the thing at all. Reviews are, well, read for yourself?
https://www.tripadvisor.com/Attraction_Review-g488299-d195537-Reviews-Blue_Grotto-Anacapri_Island_of_Capri_Province_of_Naples_Campania.html
We stayed on the island 2 nights, skipped it based on what I'd read, and didn't feel like we'd missed anything. But I don't think Capri is a great 1/2 day trip either. if you are going during the summer/early fall, the funicular and buses will be VERY busy and will slow you down. If you intend to explore off the mobbed main piazzas and more easily reached scenic spots, it's going to take time, although well worth the effort! Is there a reason you can't get there earlier?