The human immunodeficiency virus (HIV), which causes a global epidemic, targets CD4 T cells and persists due to various factors, including drug resistance, making effective treatment challenging. This paper develops a comprehensive mathematical model of within-host HIV dynamics that captures both cell-to-cell transmission and cell-free virus infection. We analyze the model’s equilibria, establishing existence and stability criteria based on the basic reproduction number, and validate these findings through numerical simulations. Sensitivity analysis highlights critical parameters influencing HIV persistence and progression, particularly the contributions of transmission modes to viral load. To inform treatment strategies, we develop an optimal control system using Pontryagin’s Maximum Principle, specifying conditions for minimizing viral load and resistance spread through optimized therapy. Numerical results show that tailored treatment significantly impacts HIV control, offering insights into therapeutic approaches that could improve patient outcomes by effectively reducing viral loads and delaying resistance. These findings underscore the importance of considering dual transmission modes and resistance mechanisms in HIV treatment strategies.