The formation process of Uranus and Neptune is numerically explored. By using a simple two-body approximation based on Opik's formalism, it is found that the accretion process in the outer planetary region usually leads to the formation of two large planets, the mass of the farther one being in most cases somewhat larger than that of the closer one, in agreement with the mass relation between Uranus and Neptune. In addition, some other protoplanets of up to a few Earth masses are found to form along Uranus and Neptune, which probably led to megaimpact events during the late accretion stages. The orbits of the two outermost planets are found to migrate by several AU during the course of their accretion process from birthplaces located at about 15-25 AU, in agreement with previous results obtained from a simpler numerical model (Fernández and Ip, Icarus 58, 109, 1984). These results suggest that the accretion zone that gave rise to the outer planets was originally confined closer to the Sun than their current orbits may suggest. The sharp cutoff of planet masses at Neptune's distance may be explained as due to the orbital expansion of proto-Neptune by several AU, that allowed it to accumulate bodies from a wide zone of the protoplanetary disk. The radial expansion of the orbits of the outer planets allowed them to pass through low-order commensurabilities, where they were temporarily locked until a strong perturbation disrupted the commensurability. Prolonged residence times of the accreting Jovian planets in commensurable orbits, may thus explain the current near-resonant structure of their orbits.