When a druid reaches level 3, his animal companion earns two hit dice. Do I have to roll them to give him more hp or is it only a number to use, for example, for spell effects? The manual also says that they "gain a Constitution modifier", so I would roll them, but a level 3 animal companion might have more hp than the druid itself, which seems a bit overpowered to me.
Bonus Hit Dice improve an animal companion's hit points
Unlike with a familiar (Player's Handbook 52) that receives effective Hit Dice for, for example, resisting a sleep spell effect but still keeps its actual HD so that, for example, it is easily slain by an energy drain attack, an animal companion (36) receives bonus HD that are like actual HD in pretty much all ways except that the HD don't count toward increasing the animal companion's size (see this question). (While ability score increases at each 4 HD aren't listed in the PH as one of the effects of bonus HD, it seems they are—see this question.)
So, yes, while the DM determines how these HD add their hp to to the animal companion's maximum hp—whether the DM rolls the HD, the player rolls, or the average is taken—, the animal companion's maximum hp improve due to the bonus HD it receives from being an animal companion.
This means that it's possible for an animal companion to have more hp than its druid master and, in some cases, the party's fighter, but unlike most party's fighters, the animal companion does very little until the Handle Animal skill is used to make it perform a trick. This lack of independence tends to mean that the animal companion isn't particularly overpowered, although an animal companion is often considered at low levels a superior combatant when compared to the typical fighter that uses only material from the Player's Handbook. However, the druid class overall is one of the game's most powerful classes, and the animal companion—again, especially at low levels—contributes to that ranking.
The animal companion gets hit dice, with all they entail, including hp. So if you roll hp, roll them for the animal companion (for a variety of reasons I strongly recommend using the average instead for hp from HD).
The companion gains the full benefit from increased Hit Dice, including [...]. The animal companion, however, does not [...].
While the “including” clause does not list hp, “including” implies that the list is not exhaustive and we should expect there to be more to “the full benefit from increased Hit Dice”—like hp. And the following list of exceptions does not include hp either, it only mentions size increases.
Contrast the animal companion with the familiar, which really does get the “counts as” effective HD that you describe in the question.
For the purpose of effects related to number of Hit Dice, use the master’s character level or the familiar’s normal HD total, whichever is higher.
The familiar has one-half the master’s total hit points (not including temporary hit points), rounded down, regardless of its actual Hit Dice.
The wording is completely different, and importantly, the familiar rules describe an alternate way for the familiar’s hp to grow with their master’s level. Without some kind of hp growth, a companion isn't going to be able to survive.
As for being overpowered, yes and no. The animal companion is a very, very strong feature—but it’s a distant third to wild shape and druid spellcasting in terms of the power of druid class features. The spellcasting alone would make the druid one of the most powerful classes in the game, and then they get very potent additional class features in the animal companion and wild shape on top of that.
Ultimately, the druid is still one of the best classes, not the best. Cleric and wizard have strong claims to being even stronger—and at the high end, it’s all about the spells so even though the other druid features are very very strong, they don’t really change things relative to other very very strong classes all that much. Unless you go after the spells, there just isn’t anything to really be done about the imbalance.
But if you wanted to do something about the animal companion and wild shape, many recommend the Player’s Handbook II shapeshifting variant—that replaces both the animal companion and wild shape with the much weaker shapeshifting option. Others recommend swapping the animal companion of the druid and ranger classes, so the ranger gets the full-level one and the druid gets the half-level one. I have used both, they’re fine, but mostly I don’t bother—the spells are the thing anyway, and the animal companion and wild shape are more interesting, so I prefer to just leave them alone. Then again, I play E6 to limit spellcasting.