Earth formed around 4.54 billion years ago by accretion from the solar nebula. Volcanic outgassing probably created the primordial atmosphere and then the ocean; but the atmosphere contained almost no oxygen and so would have been toxic to most modern life including humans. Much of the Earth was molten because of frequent collisions with other bodies which led to extreme volcanism. A "giant impact" collision with a planet-sized body is thought to have been responsible for forming the Moon. Over time, the Earth cooled, causing the formation of a solid crust, and allowing liquid water to exist on the surface.
Hope this helps. :)