Stochastic Dynamics, Filtering and Optimization