Optimal vaccination policy to prevent endemicity: a stochastic model