In this paper, to investigate the synthetic effect of PrEP (pre-exposure prophylaxis) and ART (antiretrovial therapy) on HIV transmission among MSM (men who have sex with men) in heterogenous environment, an realistic HIV epidemic model with spatial diffusion is established. Here, HIV infectious people are divided into three immunity based compartments, i.e., CD4+ T cell count less than 350, between 350 and 500, and more than 500, respectively. The basic reproduction number $R_0$ is established and proved as a threshold parameter: The global asymptotic stability of the disease-free steady state holds for $R_0<1$, and the disease will be present if $R_0>1$. Considering the substantial advantages of PrEP and ART in controlling HIV transmissions among MSM, the optimal control problem is presented for the case of positive constant diffusion coefficients, which minimize the total population of susceptible individual and HIV infected individual, the cost of PrEP and ART thearpy. As an illustration of our theoretical results, we conduct numerical simulations. We also conduct an optimal control case study where model parameters are estimated from the demographic and epidemiological data from China. This work suggests: (1) Spatial factors cannot be ignored during the HIV intervention; (2)Taking the PrEP intervention measure for HIV transmissions among MSM as early as possible will help to improve the control efficiency and reduces its cost; (3) Reducing the PrEP drug costs will promote the efficiency of PrEP treatment in preventing the spread of HIV among MSM.