A constitution score represents a creature's metabolism, stamina, resistance to disease/poison, etc. However, it also represents the strength of a creature's "life force" - note that negative energy effects and death effects require Fortitude saves. Therefore, why not give constructs an equivalent "animating force", and undead an "unlife force"?

All these forces would still be called Constitution, and constructs/undead would still be immune to nonmagical poisons/diseases/etc., but it opens up the possibility of bonus hp per HD and ability damage/drain from specific anti-construct and anti-undead sources.

For preexisting undead creatures, give them a Constitution score equal to 10 or their Charisma score, whichever is higher. (a measure of their spiritual strength)

For preexisting constructs, drop any bonus construct hp from their size and give them a Constitution score equal to 10 or their Strength score, whichever is higher. (a measure of the strength of their building materials)

Alternatively, give these creatures a Constitution score of 10 plus their CR (no iron golems with 33 Con this way!).

Constructs and undead retain all their current immunities, but can now take Constitution damage/drain from specific sources. For example, lesser restoration might cause 1d4 points of Constitution damage to an undead creature (and even inflict a supernatural form of fatigue as well!). Similarly, rusting grasp might cause Constitution drain to an iron golem.

For something really crazy, I had also considered giving undead "negative Constitution" scores and negative hp totals, but that got too complicated way too quickly :D