It sounds like you have at least one electrical issue. Iíd first find out what code was thrown to give you the CEL. Second, i would figure out what your battery is not staying charged. If the battery is draining while the truck is sitting doing nothing, then you have a parasitic battery drain. In other words, a ground wire shorted to power somewhere. They arenít that hard to pin-point. Here is a very good step-by-step instructions on how to figure out where the issue is.
Once you have that figured out, and your battery is fully charged, then start trying to find the issue that is making the truck die suddenly. That too will be an electrical issue. It may very well be the same issue causing your battery drain. But start by checking the battery connections. Make sure they are clean & tight. If not, take them off and hit them with a wire brush and then re-install. Sudden shut-down issues are usually a loose connection or broken wire somewhere.