for any reason the engines stopped working, and there's nothing near or far that could be used for landing, except the endless water.
You have answered your own question... if it is impossible to reach solid land, they attempt a water landing ("ditching"). The ideal is always to land (or "water" in this case) at the slowest possible forward speed and the slowest possible vertical speed, which are competing desires due to energy conservation (the laws of thermodynamics). At a guess, in the case of an ocean landing the pilots will accept a faster forward speed in exchange for the lowest possible vertical speed—a "belly flop" into the water is more likely to instantly damage the aircraft than a fast landing.
In the case that there is a landing strip within gliding distance, they will attempt to get to it, as one famous flight did. Aircraft do not "fall out of the sky" when they lose engine power; they are able to glide by trading potential energy (altitude) for kinetic energy (forward speed). The glide ratio of an aircraft describes how far it is able to travel horizontally per unit altitude with no engine power; for an airliner this number is in the range of around 12:1–17:1.
Of course being in this situation in the first place is highly unpleasant, so regulators make certain rules to make it unlikely. In the past this meant requiring three or four engines, or more, on transoceanic aircraft; the idea is that the likelihood of all engines failing is very low. As manufacturing has gotten better and engine reliability has increased, aircraft with only two engines are now certified to travel between continents due to a program called ETOPS. Such planes have demonstrated single-engine performance that allows them to continue to a safe landing area on only one engine from any location on their route.
ETOPS only addresses engine reliability, though. A more systemic issue, like running out of fuel, will cause problems whether the aircraft has one, two, or eight working engines.