General optimality criteria for multiphase multireaction chemical equilibrium