Before we came to earth, our spirits lived with Heavenly Father who created us. We knew Him, and He knew and loved us. It was a happy time during which we were taught God’s plan of happiness and the path to true joy. But just as most of us leave our home and parents when we grow up, God knew we needed to do the same. He knew we couldn’t progress unless we left for a while. So he allowed us to come to earth to experience the joy — as well as pain — of a physical body.
Each time we make a poor choice with painful consequences, that decision leads to unhappiness — sometimes immediately, sometimes much later. Likewise, choosing good eventually leads to happiness and helps us become more like Heavenly Father.
Talk Source: http://mormon.org/plan-of-happiness