Spin transfer torque magnetic random-access memory is widely considered as a promising candidate for a next generation cache, with a core device of magnetic tunnel junction. The MgO/CoFeB/W/CoFeB/MgO structure as recording layer for magnetic tunnel junctions is of great interest due to features such as strong perpendicular magnetic anisotropy (PMA) and thermal stability. However, the origin of correlation between PMA and interlayer exchange coupling (IEC) in this structure remains unclear. In this paper, we investigate the PMA and IEC in the MgO/CoFe/W/CoFe/MgO structure with first-principles calculation. IEC with long and short period oscillations is observed, which results in much different magnetic anisotropy energies at CoFe/W interface in MgO/CoFe/W/CoFe/MgO structure compared to MgO/CoFe/W structure. Furthermore, we find an oscillation of magnetic anisotropy energies in ferromagnetically coupled MgO/CoFe/W/CoFe/MgO structure. According to k-space and band-decomposed charge-density analyses, this oscillation can be elucidated with quantum well states on spin-up states near Fermi energy within W layers. Thus, the correlation between PMA and IEC is explained by quantum well states. These findings provide comprehensive understanding of PMA and IEC in double-interface structures and pave a new way to modulate PMA with quantum well states in heavy metal layers.