  Electronic structure calculations are used to examine the magnetic properties
of Fe$_2$P-based alloys and the mechanisms through which the Curie temperature
and magnetocrystalline anisotropy can be optimized for specific applications.
It is found that at elevated temperatures the magnetic interaction in pure
Fe$_2$P develops a pronounced two-dimensional character due to the suppression
of the magnetization in one of the sublattices, but the interlayer coupling is
very sensitive to band filling and structural distortions. This feature
suggests a natural explanation of the observed sharp enhancement of the Curie
temperature by alloying with multiple elements, such as Co, Ni, Si, and B. The
magnetocrystalline anisotropy is also tunable by electron doping, reaching a
maximum near the electron count of pure Fe$_2$P. These findings enable the
optimization of the alloy content, suggesting co-alloying of Fe$_2$P with Co
(or Ni) and Si as a strategy for maximizing the magnetocrystalline anisotropy
at and above room temperature.
