Hello teresin, and welcome to cruise-chat. You should definitely book your shore excursions in advance--as far in advance as possible. Some of the more popular excursions are sold out way in advance, although the ship will sometimes add additional departures if the demand is high enough; but you can't count on that.
To know if you will have extra time to go ashore on your own, you need to know the departure and return times of your excursion, which you will know when you book. Then you compare that with your itinerary to know what time you arrive at and leave the port. You need to be back onboard at least one-half hour before sailing; but I would try to make that an hour, just to be safe.