For a simple, straightforward German expression of condolence, you can say "Mein herzlichstes Beileid zu dem tragsichen Verlust (I am very sorry for of your loss)." To nuance the phrase somewhat differently and to express sorrow at hearing of a tragedy, say instead "Es tut uns sehr leid, über den tragischen Verlust von ... zu hören."
Very often, mourners or their loved ones want to express a fondness for the departed, or a sense of what good people they were in life. In German, one can say "Er war so ein netter Mann (he was such a nice man)" or "Sie war so eine nette Frau (she was such a nice woman)." To express a shared sense of loss with the grieving, one can say "Ich werde ihn/sie sehr vermissen. (I will miss him/her very much)."
In German, as with many other languages, it is sometimes important to distinguish between familiar and more formal terms of address, especially in sensitive situations such as those often defined by loss. For example, to address social peers or people you know, you can say "Wir würden Dir so gerne Trost zusprechen, aber es fehlen uns die richtigen Worte (We would so much like to console you but can't find the words)." However, in circumstances where an elevated sense of politeness or decorum seems appropriate, you should replace "Dir" with "Ihnen." If a religious or spiritual sentiment seems appropriate, consider saying "Wir hoffen sehr, dass Sie während dieser traurigen Zeit Stärke in Ihrer Familie und in Gott finden können, (we hope you find strength in your family and the Lord at this sad time)."