Avoiding pitfalls of least‐squares inversion by using the energy‐flux error criterion