What could cause leg pain and back pain from sleeping or sitting in one position for a long time?

Nerve impingement. Back pain is common and is often treated with core strengthening. However, when it is accompanied by pain radiating down a leg, it suggests lumbar nerve impingement as well.