The Modular Energy Function: Exact Identities and a Primality Equivalence