I think the heroic code is at the heart of Beowulf. Since the people who orally composed Beowulf were pre-Christianity, they had no way of imagining an after-life. The only way to live on once you died was through stories or oral traditions.
One way to ensure being remembered was to fulfill the heroic code, with its virtues of bravery, loyalty, and generosity. Fighting bravely, maintaining loyalty to your clan or kin, and then sharing your spoils with your men or family all ensure that you will be remembered.
The heroic code was vital to the Geats and, later, the Anglos and Saxons that settled in England. These peoples were warriors and one way to ensure their continued success was through adherence to the heroic code.
If you look at Beowulf, note the reason he travels to Hrothgar's land is to battle the legendary Grendel. This is to fulfill the heroic code. Beowulf is being brave for accepting this challenge. He is being loyal by fulfilling an obligation to Hrothgar (for Hrothgar once aided Beowulf's father). Finally, Beowulf will share the spoils from the victory with his men and his people. All of these will help add to Beowulf's reputation, which will enable him to live on after he has died. These are the same reasons he chooses to vanquish Grendel's mother, and later as an old king, to battle the dragon.