Tuning quantum well states (QWSs) to govern physical properties in nanoscale leads to the development of advanced electronic devices. Here, we propose that QWSs can be engineered to control magnetocrystalline anisotropy energy (MCAE) which dominates the magnetization orientation (that is, the easy axis) of a ferromagnetic thin film. We investigate from first-principles the MCAE of the bcc Fe film on an Ag substrate. The calculated MCAE oscillates largely as Fe thickness increases agreeing well with experiments, and reaches oscillation extremes as the Fe d-orbital QWSs approach the Fermi level (E F ). Crucially, we find that this phenomenon stems from the combined effect of intrinsic spin-orbit interaction (SOI) and Rashba SOI field on the Fe QWSs, which modulates the density of states at E F as the Fe thickness varies. Moreover, this effect offers a way to tune not only the strength of magnetic anisotropy but also the easy axis of a Fe film by shifting E F within ten meV via moderately charge injection, which could realize advanced memory devices with ultra-low power consumption.