Did you replace the distributor wit a stock unit or something like an H.E.I. distributor?
Same goes for the carburetor, Stock or aftermarket?
If you have an aftermarket carb, and a stock distributor, then you have to perform what is called the "nutter bypass"(Google it) to take the computer out of the equation. On the 4.2L motor the computer controls the stock carb and the distributor, and makes adjustments to each as you are driving. If you replace the carburetor, then the only thing that the computer can adjust is the distributor, and this leads to erratic idle, and constant stalling.
'87 YJ, 4.2L built and bored, 8.5" of lift, 8.8 rear, AX15/NP 231, Tom Woods drive shafts, Flat fenders, 12,000LB winch, Custom bumpers, Rattle can paint job. Never completed...