As the object leaves the surface of the planet, it loses kinetic energy and gains gravitational potential energy. Through conservation of energy we know the loss of kinetic energy must be equal to the gain of gravitational potential energy. This gives us an equation with initial kinetic energy minus final kinetic energy (as it is the loss of kinetic energy) on one side, and final GPE minus initial GPE on the other side, taking care to remember GPE is negative.
0.5mu2 - 0.5mv2 = (-GMm/r2) - (-GMm/r1)
0.5m(u2 - v2) = -GMm(1/r2 - 1/r1)
In order to have just enough velocity to escape, the velocity must be 0 at ininity. If it was any less it would just slowly fall back to the planet. So if we make r2 infinitely large, and v = 0, we get the following:
0.5m(u2) = -GMm(0 - 1/r1)
0.5mu2 = GMm/r1
We can cancel m:
0.5u2 = GM/r1
And rearrange for u:
u = (2GM/R)1/2