I would second the ‘rPi really shouldn’t be locking up’ sentiment(specific applications can and do get buggy, and I’ve had cheap USB wifi NICs flake out on me; but actually having the system hang such that I can’t SSH in or use a local serial terminal is not good, the kernel is mature enough that just dropping dead shouldn’t happen.)
If you haven’t already tried it, you might want to test with a nicer power supply(the ratings on some USB-charger widgets are very, very, optimistic and the power quality atrocious; USB cables can also be an issue, some of the cheapies have surprisingly high resistance on power and ground, and can cause some voltage droop, feeding the header pins directly with thicker cable might be worth looking at, especially if your Pi is any substantial distance from its PSU). It might also be worth testing a different SD card: some models hold up pretty well; but some are barely qualified to successfully store pictures and can start flaking out when used as an OS boot volume.
As for UPS, if you can find one of those ‘portable USB charger’/‘battery bank’ units that they sell for recharging phones and the like that will accept being connected to a charger at the same time as a device is connected for power, that would make an inexpensive and compact option.
Another alternative is to take advantage of the wide availability of 12 and 24v to USB adapters sold for powering electronic gizmos in the car; and use those to connect the Pi to a UPS running at one of the conventional lead-acid battery bank voltages without incurring unnecessary inverter losses. 12 and 24v systems are going to be vastly more common, and inexpensive per unit power, for mains-connected UPSs; but there isn’t a lot of point running an inverter when you can get efficient DC-DC converters designed to power 5v loads.