A general approach of least squares estimation and optimal filtering