I would like to know if it is possible to completely replace butter/margarine with egg yolks in cookie dough? Or in any other kind of butter-based dough while we are at it. And, if it is possible to do it, what are the basic principles of such substitution?
Butter and egg yolks have very different profiles in terms of their uses in recipes and constituent parts.
Butter usually has 80-85% fat by weight, while egg yolks are only about 25-30% fat. Butter has only a trace amount of milk proteins, while egg yolks typically have 15% or more protein by weight. Butter has only a small amount (about 15%) of water, while egg yolks are about 50% water. And then there are all sorts of differences in trace chemicals, which also have big effects when cooked (e.g., eggs coagulate, while butter melts).
I've never tried such a strict substitution myself. But extra egg yolks are common in many baked goods, and I've seen people substitute a single egg yolk for a small amount of fat or the reverse. As for the effect of additional egg yolks in cookies, Serious Eats summarizes:
Egg yolks also provide some moisture and protein, but more importantly they provide a well-emulsified source of fat. When cooked, egg yolk forms a tender protein coagulum that can keep cookies tender and fudge-like. A high proportion of egg yolk leads to a more brownie-like texture in a finished cookie.
Meanwhile, if you lose butter, you'll be eliminating significant amounts of fat and flavor. The texture will also be altered significantly: since butter melts during baking, it contributes significantly to cookie "spread" rate. (The extra moisture from egg yolks may help the cookie dough to spread, but it may make it harder to work with.) If your recipe involves creaming butter and sugar together, the texture may also be affected, because creaming introduces air bubbles that can lighten the cookies. Eggs too contribute to leavening, but that effect is mostly from whites.
In general, egg yolks are going to provide much more moisture than butter but lower (though still important) amounts of fat. You may need to play with the other liquid proportions to get a useful batter. And the protein and tendency to coagulate will alter the structure of the cookies considerably.
My guess is that most cookies with such a substitution will come out fairly dense with an odd fudge-like texture and "eggy" flavor. If you're substituting a single egg yolk for a small amount of butter, it might work with a little tweaking. But if your recipe has large amounts of butter, the final cookies will be very different and perhaps unpalatable. In that case, you'll probably have to substitute a few different things for the butter to produce acceptable results (specifically something else to add sufficient fat and to balance the flavor of the cookies).
Or, an easier solution would be to find a recipe or type of cookie that doesn't require butter. Producing good results when removing one of the major components of a recipe will often require significant amounts of experimentation.