A loose ground can cause all kinds of electrical problems, not just the usual dim lights/won't start condition. This is because just about everything runs through the computer(ECU). It takes a very small deviation in the voltage for the computer to trip a code, and that is what can happen with a loose ground.
In addition to a loose ground, your batteries can also be at fault. Batteries fail due to excessive vibration or shocks. Everything can look OK on the outside, but they can fail internally.
In summary, when you have two or more electrical problems that are happening simultaneously, checking grounds is one of the first places to start.