Solution of the boundary value problem for optimal escape in continuous stochastic systems and maps