In this article, a stochastic SIR epidemic model with treatment rate in a population of varying size is proposed and investigated. For the stochastic version, we briefly discuss the existence of global unique solutions and using the Lyapunov function, the disease free equilibrium solution is globally asymptotic stabe if $\mathcal{R}_0\leq1$ and the endemic equilibrium solution is obtained when $\mathcal{R}_0>1$. The main attention is paid to the $p$th-moment exponentially stable on the system, proved under suitable assumptions on the white noise perturbations and the optimal control for the deterministic model. Finally numerical simulations are done to show our theoretical results and to demonstrate the complicated dynamics of the model.