Optimal control and pathwise nonlinear filtering of nondegenerate diffusions