This may be of interest: https://www.reddit.com/r/AskAnthropology/comments/6uqpar/what_is_the_oldest_religion_that_we_know_of/
Your 2 questions are vastly different, as humanity is around 300,000 years old, but oldest written records are around 5,000 years old. You're better off rephrasing your question and posting in the appropriate subreddit depending on which question you're most interested in.
Part 1
So this is a massive question. Regretfully, in some cases, we don't know how the religion was created, or why it was formed, as the religious stretches too far back and we don't have the sources. I'm thinking primarily Hinduism. But we do have ideas on others ones. I'll start with Christianity though, as we have a pretty good picture there.
There have been a number of books written on the subject, but one of the most thorough texts on the subject was written by John Dominic Crossan, aptly titled, The Birth of Christianity. While his position has largely been accepted, it hasn't been without some challenge. Works such as From Jesus to Christ, by Paula Fredrickson and From Jesus to Christianity, by L Michael White have also added a great deal to the understanding of the formation of Christianity.
One thing we must first do though is place Christianity in a historical context. Specifically, we have to place Jesus in a historical context. In the 1980s, what N.T. Wright has deemed the Third Quest for the Historical Jesus was beginning. Two important figures in this quest are Geza Vermes and E.P. Sanders. What these two authors did was place Jesus in his Jewish context. E.P. Sanders wrote Jesus and Judaism, while Vermes wrote a trilogy; Jesus the Jew, The Religion of Jesus the Jew, and Jesus in His Jewish Context.
What these two authors demonstrated was that Jesus was Jewish, and that he had no intention on creating a new religion. More importantly, in order to understand Jesus, you had to understand the Judaism in which he was operating in, specifically, second Temple, Palestinian, Judaism. That argument has largely become a foundation for the studies on the origin of Christianity.
As these two authors argue, Jesus never attempted to start a new religion, and was working within Judaism, and that is how he is best understood. They also help make sense of the idea of the resurrection (E.P. Sanders goes further in this regard with two other books, Paul and Palestinian Judaism; and Paul The Law and the Jewish People). Specifically, they look at the idea of a general resurrection which was present in some forms of Judaism at that time, such as Pharisaic Judaism, and what Sanders calls Common Judaism. This was the belief that at the end of time, or specifically when the Kingdom of God replaced the earthly Kingdom, there would be a general resurrection where Jewish people, and others, would be resurrected, and live in this new kingdom. The view was based on an understanding of justice. The idea was that God was a just god, and at some time, the Jewish people (and this stretched further as well) would receive justice for the turmoil that they felt on earth.
The authors then argue that during the first century, what we begin seeing is basically a boiling point. We see quite a few revolts amongst the Jews (including the First Jewish Revolt that led to the destruction of the Temple), and we see a number of Messianic claimants rising up, and ultimately being shut down by Rome. This is the context Jesus is brought up in, and it greatly influenced his message.
Now, John Dominic Crossan goes a bit further than this. One of the big ideas that Crossan introduces is the idea that Jesus was a Mediterranean Jewish Peasant (personally, I disagree with the idea that Jesus was a peasant, and Crossan has a number of opponents to the claim, but the general idea is rather sound).
Whether or not Jesus was a peasant isn't all that important here though. What Crossan does point out (in The Birth of Christianity) is that the Jewish homeland had been under pagan control for centuries. However, during the rule by Persians and the Greeks, only one revolt occurred, and that was over four hundred years. But in the 200 years that Rome controlled the area, there were three major revolts. Crossan argues that this was because during Roman rule, the Jewish population in Palestine, which was fairly poor and rural, were overly oppressed. With the idea of a divine justice coming, this nearly guaranteed a clash, and as I mentioned before, this was the environment Jesus was born in.
So, Jesus, as these three authors show, was born in a time and place that was set for revolt. And Jesus enters into this environment with an apocalyptic or eschatological message about divine justice. That soon the Kingdom of God would replace the earthly kingdom (which was Rome). As the Gospels agree, the fate of Jesus was death as a criminal in the eyes of Rome.
But even with the death of Jesus, Christianity isn't formed. As Vermes and Sanders pointed out, the idea of resurrection wasn't all that unique. It was an idea within Judaism, and it was attached to the general resurrection. Now most scholars will argue that Jesus wasn't really resurrected. Crossan, in "The Historical Jesus," argues that Jesus was probably buried in a shallow grave and eaten by dogs. But, the idea that Jesus had been resurrected was being spread. Yet, again, this was within a Jewish context.
So we have two aspects here now. Fredriksen, in From Jesus to Christ, points out a very important aspect. The Jesus movement continues after the death of Jesus, and who takes this up is his brother, James, along with Peter and John (two former disciples). This group is called the Pillars, and they are at the center of the Jerusalem sect. This is still a Jewish mission, and they are operating within Jewish ideas. However, we have other individuals coming in as well, and they start spreading the message to Gentiles. One of the obvious individuals is Paul.
As for Christianity, it was a first century development out of 2nd temple Judaism (545 BC or so). Christians believed themselves to be the fulfillment of the prophecies and promises made to the people of Israel. In fact, Christians modeled their worship after temple/synagogue worship. However, this was rejected by the Jewish people who did not convert to The Way (one of the original titles of Christianity). So within less than a decade Christianity was it's own distinct religion (40 AD).