There are many theories concerning the formation of our solar system. And much is still unknown. However, astronomers agree that solar systems form from clouds of interstellar matter called nebulae. A nebula is a very large, shapeless cloud of interstellar gas and dust (cosmic matter) floating in space. In the case of the formation of our solar system, this cloud is believed to have contained the remains of an ancient star (or stars) which exploded long ago. Eventually gravitational forces pulled this matter into our sun and planets. At first, before the sun ignited, this process took place in the darkness of interstellar space.
Star Formation: The sun was by far the largest of the clumps of matter which were falling together. Therefore, according to the laws of thermodynamics, it would also be the hottest and under the most pressure. When this clumping material (which is mostly hydrogen) becomes hot enough, it will ignite -- quite literally as a giant, continuously burning, hydrogen bomb. This nuclear fusion takes place way down in the center of the newly formed star. Eventually, its energy will reach the surface and the star begins to shine.
Stars such as our sun generate a "wind" of sorts. This "wind" is comprised of elementary particles which "blow" away from those stars at about a million miles per hour. A new star will sporadically flare and generate this "wind" in bursts. This "wind" would eventuallyclear away the remaining nebular dust which would have been surrounding the new star and its planets until this time.
With time, there would be less dust. At some point the solar system would have been a pretty hazy place; sunlight would have bounced around in a moderate amount of interplanetary dust. This means that the early earth was probably lit from all sides. As the interplanetary dust continued to clear, shadows would become more distinct until the earth would have a "day" side and a "night" side as it does today.
From the absence of heavy inert gasses in our present atmosphere, scientists conclude that the earth's original atmosphere must have been entirely stripped away at some point in the past see here (p.96) and here (p.260). One theory is that this was accomplished by a huge burst of solar wind from a giant sun flare. Possible evidence of this flare is seen in the differences between the four inner planets and the four outer planets (Pluto no longer being a proper planet). The four inner planets (Mercury, Venus, Earth, and Mars), are all essentially bare rocks, having relatively thin atmospheres. These four may all have been within range of the solar flare and had their original thick atmospheres removed. This is actually a good thing, because those atmospheres were made out of poisonous gasses. Mercury, being closest to the sun, would have received the worst part of this flare. It was close enough that a significan fraction of its lighter rocky crust may also have been blown away. Mercury does have a higher iron content than the others in our solar system. Its oversized iron core is closer to what might have been expected from a planet having about twice the mass that Mercury presently has.
The next four planets (Jupiter, Saturn, Uranus, and Neptune) are gas giants with rocky cores see aslo here. These cores alone are presently believed to be more massive than the four inner planets are. It appears that these giants were out of range of the solar flare; they still have their original atmospheres which are thousands of miles thick. Interestingly, separating the inner and outer planets, at about the suggested limit of this flare, is a cloud of debris called the asteroid belt. At least some of these asteroids may be the remains of any small moons which might originally have been circling the inner planets, or debris blown off of these planets' original surfaces. Neither of the two closest planets to the sun have any moons; the earth has only one giant moon which is nearly a planet in its own right. Only Mars, farthest out of the four, still has any small moons.
A blast this powerful would have removed the earth's original oceans as well as its atmosphere. This water, along with the original planetary atmosphere, probably would have been blown clear of the solar system; most of it it is probably somewhere out in the Kuiper belt. The makings for the present atmosphere and oceans -- nitrogen, carbon dioxide (including oxygen), and water were safely held (chemically bound) in the earth's rocks. With time, these elements were released by volcanic eruptions and hydrothermal activity such as geysers see here (p.421).
Although the earth was originally quite hot (possibly hot enough to boil water), it eventually cooled sufficiently that this volcanic water could condense upon it to form the present oceans. The remainder of this story would probably be of more interest to geologists than to astronomers.