It is narrated from Sayyidah Umm Salamah (may Allah be pleased with her) that the Messenger of Allah (peace and blessings be upon him) said: "When you are present with the dying, say good things, for the angels say Amin to whatever you say." She says: When Abu Salamah (may Allah be pleased with him) died, I said: O Messenger of Allah (peace and blessings be upon him), what should I say? He (peace and blessings be upon him) said: "Say: 'Allahumma ighfir lahu wa a'qibna minhu 'uqba salihah' (O Allah, forgive him and grant us a good successor after him)." She says: Then Allah Almighty gave me someone better than him as a companion: the Messenger of Allah (peace and blessings be upon him).
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجنائز / 6601
It is narrated from al-A'mash (may Allah have mercy on him) that he (peace and blessings be upon him) said: "Say this when you are present with the sick or the dead."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجنائز / 6602