The ferry leaves Battery Park every 20-40 minutes, but you need to allow time for clearing security (if you purchase your tickets in advance). You'll need even more time if you want to buy tickets once you arrive at Battery Park.
After about a 10 minute ride, the ferry will stop at Liberty Island first. Whether you want to visit the Statue of Liberty or not, you'll need to disembark. If you want to tour Liberty Island or enter the Statue of Liberty, you can catch a ferry on to Ellis Island whenever you are done. You'll need a Monument Pass in order to visit the museum or enter the pedestal of the Statue of Liberty. Monument Passes are free, but there are a limited number available (they are included with advanced purchase Reserve Tickets, but available on a first-come, first-served basis for other visitors).
Another 10 minute ferry ride will bring you to Ellis Island. Here you will want to plan to allow at least an hour to visit the Ellis Island Immigration Museum. I highly recommend taking the free Ranger Led Tour and also allowing yourself time to explore the museum on your own.
Once you are done at Ellis Island, you can board the ferry again to return to Battery Park. The ferry leaves Ellis Island every 20 minutes. Be sure to get the ferry bound for Battery Park, as there are also ferries going back to Liberty Island for visitors who took the ferry from New Jersey.
Statue Cruises Website offers a helpful Tour Combination Schedule that will give you a sense of how long it will take to visit either or both islands, depending on what you intend to do (audio tours, museums, etc.).