The electrochemical oxidation of morphine (MO) and codeine (COD) has been investigated by the application of a novel glassy carbon electrode modified with a hydroxyapatite-Fe3O4 nanoparticles/multiwalled carbon nanotubes composite (HA-FeNPs-MWCNTs/GCE). The modified electrode worked as an efficient sensor for simultaneous determination of MO and COD in the presence of uric acid. Response surface methodology was utilized to optimize the voltammetric response of the modified electrode for the determination of MO and COD. The amount of HA-FeNPs in the modifier matrix (%HAFeNPs), the solution pH and the accumulation time were chosen as the three important operating factors through the experimental design methodology. The central composite design as a response surface approach was applied for obtaining the optimum conditions leading to maximum oxidation peak currents for MO and COD. The differential pulse voltammetry results showed that the obtained anodic peak currents were linearly proportional to concentration in the range of 0.08–32 μM with a detection limit (S/N = 3.0) of 14 nM for MO and in the range of 0.1–28 μM and with a detection limit of 22 nM for COD. The proposed method was successfully applied to determine these compounds in human urine and blood serum samples.