We present an efficient heating/cooling method coupled with chemistry and ultraviolet (UV) radiative transfer, which can be applied to numerical simulations of the interstellar medium (ISM). We follow the time-dependent evolution of hydrogen species (H 2 , H, H + ), assume carbon/oxygen species (C, C + , CO, O, and O + ) are in formation-destruction balance given the non-steady hydrogen abundances, and include essential heating/cooling processes needed to capture thermodynamics of all ISM phases. UV radiation from discrete point sources and the diffuse background is followed through adaptive ray tracing and a six-ray approximation, respectively, allowing for H 2 self-shielding; cosmic ray (CR) heating and ionization are also included. To validate our methods and demonstrate their application for a range of density, metallicity, and radiation field, we conduct a series of tests, including the equilibrium curves of thermal pressure vs. density, the chemical and thermal structure in photodissociation regions, H I-to-H 2 transitions, and the expansion of H II regions and radiative supernova remnants. Careful treatment of photochemistry and CR ionization is essential for many aspects of ISM physics, including identifying the thermal pressure at which cold and warm neutral phases co-exist. We caution that many current heating and cooling treatments used in galaxy formation simulations do not reproduce the correct thermal pressure and ionization fraction in the neutral ISM. Our new model is implemented in the MHD code Athena and incorporated in the TIGRESS simulation framework, for use in studying the star-forming ISM in a wide range of environments.