The Egyptian religion have hieroglyphic texts on the walls of the pyramids, hence known as the Pyramid Texts. The subjects are religious, funereal and mythological.
The oldest of these pyramids (and with these texts) is the pyramid of Unas, dated to 24th century BCE, and located in Saqqara. Unas was the last king of the 5th dynasty (Old Kingdom). 4 other pyramids that have the Pyramid Texts are from 6th dynasty. The Great Pyramids of Giza (4th dynasty) may be older these pyramids of Saqqara, but they don't have texts.
Older than Pyramids of Giza, are the 3rd dynasty pyramids, built in Saqqara. All these pyramids were built in connection to the sun god Re. The centre of Re's worship was located in Iunu, which the Greek called Heliopolis, and the bible called On and has been the centre of worship since the 3rd dynasty.
In any case, the Pyramid Texts are than all the texts that Rakhel listed in her post, the Origin of Major Religions. However, there are many evidences that religion in Egypt existed before Iunu, where many different gods existed in the predynastic period.
The purpose of the pyramid was not merely a tomb for a ruler. It was the symbol of Re, and the afterlife. According to the Pyramid Texts, a king will ascend a ladder (a literal ascension) to reach the bark (boat) of Re. The Egyptians viewed the boat as the sun, which traverse the sky. Reaching this solar boat (bark) or the sun is like reaching heaven. The pyramid is the symbol of that ladder.
This afterlife is different to the Osiris one. Whereas in the pyramid age, only a king be resurrected and reached the solar boat of Re, but in the later age, the Underworld is a dark place, where Osiris rule as king and everyone can be ascended. He will be judged by the jackal-headed god Anubis on the scale, who will record the weigh of person's soul (ba) by the iblis-headed god Thoth. The person's soul is called a ba, and is drawn as either a miniaturized human or the shape of heart. If the soul weigh heavier than the Feather of Truth (or Feather of Maat) then the ba (soul) or heart is eaten by the Devourer, called Ammit. If the scale is "balanced" or the Feather of Truth weighs heavier than the ba, then the spirit akh of the person will go to Field of Reeds, which is Egyptian version of the Greek Elysian Field or Christian heaven.