In this paper, the dynamical behavior of a stochastic SQEIAR epidemic model is investigated. First of all, we establish sufficient conditions for extinction of the diseases. Then the sufficient conditions for the existence of an ergodic stationary distribution of the positive solutions to the model are obtained by constructing a suitable stochastic Lyapunov function. The existence of stationary distribution implies stochastic weak stability. Furthermore, the optimal control problem is considered to provide a theoretical basis for the prevention and control of the disease. Finally, the theoretical results are verified by numerical simulations.