Invariance theorems of stochastic stability, and application to identification and adaptation for linear systems