HIV interaction with the immune response is modeled mathematically. Initially, a detailed model is proposed that consists of a system of differential equations including immune cells (antigen presenting cells, T latent infected cells, T actively infected cells, resting T cells, helper T cells, inactive cytotoxic cells and active cytotoxic cells) and viral particles. Then, stability conditions are given from the basic reproduction number and numerical simulations are performed. From this it is possible to conclude what are the most influential parameters to reduce infection. From the initial model, a control problem is formulated in order to determine the most appropriate type of intervention to ensure high levels of activated T cells and immune response. Five different control strategies based on antiretroviral are evaluated to conclude that a strategy of constant control, obtained as the average value of optimal control, provides satisfactory results.