Hit dice (or HD) is roughly equivalent to a monster's level and gives the approximate hit points the monster has. Normal calculation for monster's HP is total of hit dice amount of 8-sided dice. Exceptions are golems, riders, special "fixed" HP monsters (which are usually uniques), adult dragons, elementals on their home planes, and HD:0 monsters.
When a monster is generated, the number of hit dice it gets can vary. Each monster type has a base HD allotment. If this is higher than the current dungeon level, its HD are decreased by one; otherwise, HD are increased by one-fifth the difference. Then, if its base HD are less than your current experience level, they are increased by one-quarter the difference. This will never take the monster above 1.5 times its base HD (rounded down) or above 49. 
When the player is polymorphed into a monster, the status line shows HD instead of experience level. Player's hit points are also usually HD times d8. Exceptions to this are golems, adult dragons, elementals on their home planes, and HD:0 monsters.