Make the dough: In a large bowl, whisk together the flour and salt. Add the egg, sour cream, and water, then mix until a shaggy dough forms.
Knead and rest: Knead on a lightly floured surface for 8–10 minutes until smooth and elastic. Cover with a damp towel and let rest for 30 minutes.
Cook potatoes and make filling: Boil the peeled, cubed potatoes until fork-tender, then drain well. Mash until smooth, then mix in cheese, butter, salt, and pepper. Cool to room temperature.
Roll and cut: Roll the rested dough to about 1/8-inch (3 mm) thick. Cut 3-inch circles using a round cutter or drinking glass.
Fill and seal: Place about 1 tablespoon filling in the center of each circle. Fold into a half-moon and press edges firmly to seal; crimp with a fork for extra security.
Boil: Bring a large pot of salted water to a gentle boil. Cook pierogies in batches (6–8 at a time) until they float, then boil 2–3 minutes more. Remove with a slotted spoon and drain.
Optional pan-fry and serve: Sauté sliced onion in butter until golden. Pan-fry boiled pierogies in butter until lightly crisp, then serve with onions, sour cream, and optional bacon.