It means that a person is lucky enough to have two things that they want; a win-win situation; has his/her cake and can eat it too.
Example:
A person with allergies to cats will usually not be able to own a cat. However, having a hairless cat would allow the person to own a cat. Owning a cat WITHOUT the worry of allergies is the best of both worlds.
Example:
A person who want to be in-charge of a company but not be in-charge of customer complaints wouldn't want to be the boss, too much stress. BUT, if there were a customer complaint department that would deal with complaints while the person was in-charge of the workers, that would be the ideal situation for the person - the best of both worlds.
Hope this helps!