Obviously they are a reference to the Seven Dwarfs from the tale Snow White.
They reappear in Shrek 2 where they forge a wedding ring with the words "I Love You" in flaming letters engraved on it, giving it to Shrek, who gives it to Fiona. The ring is a allusion of the One Ring from Lord of the Rings.
One of the dwarfs appears in Shrek the Third as a present to Fiona on her baby shower given to her by Snow White. That same dwarf appears at the end of the film asking to babysit The Ogre Triplets, but ends up getting stuffed with a baby bottle and the door slammed on him by Shrek. This dwarf probably is Grumpy. The name of Dopey (one of the 7 dwarfs) is also referenced in this film as a tattoo on Snow White's arm.
Another dwarf appears in Scared Shrekless. It can be assumed that he is Happy.
They also appear in Shrek 2: The Video Game where the player has to rescue them.
- It is unknown if they bear the same names as the dwarfs in the Disney film based on the fairy tale, but it is assumed they do, as one of them is named Dopey (because Snow White has a tattoo on her arm with Dopey's name written inside a heart) and it can be assumed that one is named Happy (since one of them said "I am NOT happy!" in Scared Shrekless).
- Grumpy marries Princess Pea and has one son named Farquaad. Thus Farquaad would be the nephew to the other 6 Dwarves.