Mix flour, water, and egg and salt together. Knead on a lightly floured surface until smooth. Cover dough with bowl and let rest for 30 minutes.
Boil potatoes until soft. Drain and rinse. Add cheese. Let stand a few minutes until cheese melts. Then fold potatoes and cheese together.
Roll out dough about 1/8-inch thick. Cut into 3-inch squares. Fill each square of dough with one teaspoon of potato and cheese filling. Fold in half and pinch ends together to seal. Drop in hot boiling water and simmer for 8 minutes. Melt butter in a skillet and add onions and garlic till softened. Drain pierogies and add to the butter. Fry in butter a few minutes until heated through. Salt and pepper, to taste.