These credits are explained in IRS Publication 970 "Tax Benefits for Higher Education" as well as Chapter 35 of IRS Publication 17.