How do you ask someone what he or she would prefer to be called?
I think that it is best to err on the side of being too formal. I tend to ask after I refer to their name for the first time: "It's so nice to talk with you, Dr. Smith- Do you prefer Dr. Smith or do you go by another name or title?..." Then continue with your conversation.
Additionally to Nicole's answer I'd like to mention that often you can influence people. If you introduce yourself as "Nice to meet you, I am Dr. Foo Bar, but please call me Foo" they will often introduce themselves the same way. If you are on roughly the same academic level, they might even be glad that you took a leap and they don't have to face the same dilemma you had in the first place. Of course, as an undergraduate you should not do this with a professor. But as a PhD candidate to a post doc it should be fine, in my opinion.