Why not start with offering your condolences and then using something like Barb's suggestion as well- move from formality to a more friendly approach. It's a tough topic and there's no ideal way to handle it; just letting them know that you feel and care is what matters and much more than the wording. The formal wording can help sometimes to get things started and broach the subject.
Thanks for your help. I'm pretty sure that on such sad occasions some people use phrases with a word "sympathy" in them but I can't recall any. Are they commonly used? if so, I'd appreciate if you gave me some examples.