In this study, we apply optimal control theory to an immuno-epidemiological model of HIV and opioid epidemics. For the multi-scale model, we used four controls: treating the opioid use, reducing HIV risk behaviour among opioid users, entry inhibiting antiviral therapy, and antiviral therapy which blocks the viral production. Two population-level controls are combined with two within-host-level controls. We prove the existence and uniqueness of an optimal control quadruple. Comparing the two population-level controls, we find that reducing the HIV risk of opioid users has a stronger impact on the population who is both HIV-infected and opioid-dependent than treating the opioid disorder. The within-host-level antiviral treatment has an effect not only on the co-affected population but also on the HIV-only infected population. Our findings suggest that the most effective strategy for managing the HIV and opioid epidemics is combining all controls at both within-host and between-host scales.