<p>I am thinking to use closed-loop stepper motors to prevent step loss and make the machine more accurate. What options (preferably low cost) are there for:</p>

<p><code>stepper motor + driver + encoder + microcontoller</code></p>

<p>Is building it from scratch worth it? E.g. Arduino Mega 2560 + RAMPS 1.4/1.5/1.6 + stepper motors (e.g. NEMA17) + drivers (e.g. A4988, DRV8825) + encoders (e.g. AS5047P, AS5047D, AS5048A, TLE5012B) + microcontrollers (e.g. STM32).</p>

A number of options exist, but keep in mind that cost will be a limiting factor.
(Small sidenote: cost depends on persective, financial cost does not equal mental cost. The tradeoff between buy or make depends also on your willingness to persist when things don't work right away.)
Before you start:
make sure that your printer has enough space to accomodate bigger motors.
So, what options are there?
Change your current configuration. If you are losing steps, it could very well be that it can be fixed in firmware.
Pro: No budget and nothing to lose.
Con: No shiny closed loop system. (Is that bad though?) Possibly need to configure and compile your own firmware.
MacGyver / DIY solution based on low lever components
Pro: Probably as cheap as you'll get depending on how you choose your components. Might be an interesting learning experience, not to mention the satisfaction afterwards. This could be the smallest build size you'll see in all the options.
Con: You'll need a decent amount of engineering and debugging. Might be tricky to mount the encoders.
Same as 1, but now consider using of the shelf stepper motors
with integrated encoders
.
Pro: Most robust option on a budget in my opinion due to the single mechanical piece (motor + encoder).
Con: Integrated encoders have a considerable cost and are large compared to their vanila versions.
Go for
off the shelf motor+encoder and drivers
.
Pro: No need to worry about driver configurations too much. Just plug in the numbers or set the dip switches. Very conveinient solution. Pretty much plug and play.
Con: This will already be challenging on a budget. Making a wrong mix and match might lead to unpredictable results such as drives going in overcurrent. (Which, believe me, is very frustrating for your application!)
If we are allowed to consider servo motors:
ClearPath-SD series
(Or any alternative for that matter!)
I'm just including this for completeness.
Pro: Performance wise a clear winner on pretty much any relevant level.
Con: You'll need a big budget!
Bottomline
: You'll probably want to give the first option a go before spending money. Next stop, you might want to take the second option (you already did research on different specific low level components), and if you have time to spare I'd go with that as well. If you are also on a budget timewise, I'd definively suggest to take the third option with existing driver boards.
The other options are more cost heavy and become real options in produciton environments, where downtime is also costsing money.
As to the microcontroller, take whatever you have available. Just know that more computational power will allow you to output steps faster and will allow for smoother movements. Lot's to talk about there as well!