‘The best of both worlds’ means you can enjoy two different opportunities at the same time.
“By working part-time and looking after her kids two days a week she managed to get the best of both worlds.”
Or
“By working in the city and living in the countryside, he really does get the best of both worlds.”
The exact origin of the expression is unclear, but it has religious undertones which refers to two worlds, that is life and after life. These are contrasting ideas and to have the best in both worlds meant that the person in question is truly successful.