Water, like ammonia and methane, is a primordial molecule - that is, most of it formed before the Earth did. Though some of course does form from chemical processes, this isn't so common simply because hydrogen must be locked up in other chemicals and oxygen frequently is.
Meteor impacts are likely responsible for Earth's hydrosphere but another major (and some suggest the major, given the revelations of the giant impact hypothesis) source is outgassing - water molecules being ejected into the atmosphere that had previously been trapped within the Earth, from the core on upwards.
More importantly, Earth's oceans and tectonic activity share a sort of symbiotic relationship. As the Earth continues to cool, tectonic activity is driven in part by that and the lubrication provided by water within the crust. The internal heat of the Earth forces the oceans upward, and once the Earth cools sufficiently (IIRC the Sun will boil the oceans away first), the oceans will seep back into the mantle.