The hadith is well known and you may find it in many hadith books such as sahih Muslim, sunan abi Dawod, sunan an-Nasa'i and Jami'i at-Tirmidhi (all on the authority of abu Hurrairah()):
When a man dies, his acts come to an end, but three, recurring charity, or knowledge (by which people) benefit, or a pious son, who prays for him (for the deceased). (Sahih Muslim)
A closer look at the three things mentioned in the hadith:
all these three things are things this man has gained by his own effort: For example by working (earned money to spent something as waqf), learning, educating etc.
- recurring charity (also known as waqf): This is something people will still benefit from while he is dead, so why should his book of deeds be closed on this, as his good deed still brings some benefit to others, and that's important as he still somehow does good things and they should be recorded!
- knowledge: Here applies the same as for recurring charity, it is something people may benefit from even long time after his death (even if it was just a book he bought and left as waqf)!
- a pious child who prays for him: here the child is well educated as it prays for the father (or mother) and maybe one could discuss whether the good education is the good deed that returns to the death person after death or the prayers of the child! The later is quoted in a hadith in musnad Ahmad. Note that there's no reward for parents in children who are not righteous or pious!
Imam an-Nawawi in his commentary of this hadith from sahih Muslim said:
The scholars said that the good deeds of a person end with his death, a dead person can't regain any rewards after his/her death expect for these three things, because he/she was a reason for their existence, so the child is of his own, the knowledge (teaching or left books) and also the waqf (or recurring charity). This hadith also points at the importance of marriage with the intention to have pious children etc.
He (An-Nawawi) also pointed at the fact that a-Shafi'i holds the opinion that it is allowed to perform hajj for a death person (which means this person might get the rewards for that hajj) there's also a similar discussion on fast etc.
Also the difference of opinion about rewards for reciting qur'an for a death person were discussed in the commentary. A-Shafi'i and a majority of scholars reject the idea that the death will any rewards from that!
In his commentary on sunan an-Nasa'i as-Suyuti added a quote of one of his sheikhs explaining the importance of these deeds by saying that "the grain" of these deeds still exist after their life as if they were still alive, he also discussed what kind of knowledge would be more appropriate among the possibilities (Imam as-Subki as it seems was of the opinion that compiled books are the ones with most benefit and should be of a higher value).
Imam as-Suyuti wrote a poem counting ten things which may apply under this hadith and other narrations (Source):
إِذَا مَاتَ اِبْن آدَم لَيْسَ يَجْرِي * عَلَيْهِ مِنْ فِعَال غَيْر عَشْر
عُلُوم بَثَّهَا وَدُعَاء نَجْل * وَغَرْس النَّخْل وَالصَّدَقَات تَجْرِي
وِرَاثَة مُصْحَف وَرِبَاط ثَغْر * وَحَفْر الْبِئْر أَوْ إِجْرَاء نَهَر
وَبَيْت لِلْغَرِيبِ بَنَاهُ يَأْوِي * إِلَيْهِ أَوْ بَنَاهُ مَحَلّ ذِكْر
وَتَعْلِيم لِقُرْآنٍ كَرِيم * فَخُذْهَا مِنْ أَحَادِيث بِحَصْرٍ
The ten things quoted are: spread knowledge, prayers of an offspring, planting a palm (for waqf), waqf in general, a moshaf which is inherited, staying and defending a weak port of Muslims, drill a well (leaving it as waqf), leave a river run (for example which runs through his estate, and leave it for the estate of his neighbors too), building a house (where guests or travelers can seek refuge or knowledge is spread or for worship and dhikr), and finally teaching qur'an.
See also this hadith in sunan ibn Majah:
"The Messenger of Allah said: 'The rewards of the good deeds that will reach a believer after his death are: Knowledge which he taught and spread; a righteous son whom he leaves behind; a copy of the Qur'an that he leaves as a legacy; a mosque that he built; a house that he built for wayfarers; a canal that he dug; or charity that he gave during his lifetime when he was in good health. These deeds will reach him after his death.'"