For an amazing examination of building a WordPress Theme, dissecting every detail of the modular PHP building blocks and code that goes into a full, do-it-yourself WordPress Theme, check out the The Secrets of WordPress Theming by Chris J Davis from Sillyness Spelled Wrong Intentionally.
Begin at the beginning with some basic core tips and techniques in Part 1. Then get more into the code in Part Two to understand more about building template files, including custom template files for specific needs like 404, search, and more. Chris recently introduced Part 3 which examines how to make your
home.php custom template work for you with feeds and more.
Expect more in this great series that exposes all involved in a WordPress Theme and just brushes against all the possibilities for customization when working with the power of WordPress.