<abstract><p>New stochastic and deterministic Hepatitis B epidemic models with general incidence are established to study the dynamics of Hepatitis B virus (HBV) epidemic transmission. Optimal control strategies are developed to control the spread of HBV in the population. In this regard, we first calculate the basic reproduction number and the equilibrium points of the deterministic Hepatitis B model. And then the local asymptotic stability at the equilibrium point is studied. Secondly, the basic reproduction number of the stochastic Hepatitis B model is calculated. Appropriate Lyapunov functions are constructed, and the unique global positive solution of the stochastic model is verified by Itô formula. By applying a series of stochastic inequalities and strong number theorems, the moment exponential stability, the extinction and persistence of HBV at the equilibrium point are obtained. Finally, using the optimal control theory, the optimal control strategy to eliminate the spread of HBV is developed. To reduce Hepatitis B infection rates and to promote vaccination rates, three control variables are used, for instance, isolation of patients, treatment of patients, and vaccine inoculation. For the purpose of verifying the rationality of our main theoretical conclusions, the Runge-Kutta method is applied to numerical simulation.</p></abstract>