the accumulation of cosmic dust particles into a massive object by gravitationally attracting more matter.
This is believed to be the answer to the beginning of the question.
4.54 billion years ago
Earth was a giant molten glob. Constantly bombarded by collisions with other celestial bodies, it was highly volcanic. One such collision is believed to have simultaneously shaped the planet as we know it and formed our moon.
As time passed Earth began to cool forming the crust and making it possible for liquid water from outgassing vapors to exist.
The worlds oceans were created by condensation augmented by water and ice delivered by asteroids, protoplanets, and comets.