I
Because you did not serve Hashem, your G-d, with happiness and goodness of heart when you had an abundance of everything. (Devarim 28:47). The horrific punishments of the tochacha are caused by our failure to serve Hashem with happiness.
The Rambam concludes Hilchos Lulav (8:15) as follows: "The simcha that a person rejoices in the performance of mitzvos, and in the love of Hashem Who commanded them, is a great service. One who prevents himself from this happiness is worthy of punishment, as it says 'Because you did not serve Hashem, your G-d, with happiness and goodness of heart.'"
This formulation indicates that joy is a natural outgrowth of performing mitzvos out of love of Hashem unless one prevents it. How is it prevented? The Rambam answers: One who is arrogant and accords himself honor is a sinner and a fool. But one who lowers himself is the great and honored one who serves with love. There is no greatness and honor except to rejoice before Hashem.
A prerequisite for serving Hashem with love is humility. One who is full of love for himself, whose arrogance leads him to honor himself, is unable to love Hashem with all his heart. While love of Hashem is not mentioned in the passuk, presumably the Rambam derived it from the need to serve Hashem with goodness of heart, which, in turn, requires wholehearted love of Hashem. A good, and humble, heart leads not only to proper interpersonal relationships (See Avos 2:13) but also allows for the heart to be filled with love of Hashem.
Seeking honor precludes true happiness as well. One who pursues honor, honor escapes him, since he never has enough. Happiness with one's lot is not only true wealth (Avos 4:1), but also reflects love of Hashem Who grants every person his portion. Only by serving Hashem with joy and a good heart can the punishments of the tochacha be avoided.
II
The Rambam quotes this passuk in Hilchos Yom Tov as well. The Torah mandates rejoicing on yom tov and requires gladdening the disadvantaged as well (Devarim 16:11,14). One who feasts and drinks but does not provide for the poor and embittered does not achieve this mitzva joy but only the joy of his belly (Hilchos Yom Tov 6:18). Intoxication, levity and lightheadedness is not joy; it is frivolity and foolishness. We are commanded to have joy that contains service of the Creator, and proper service of Hashem is with joy, as it says "Because you did not serve Hashem, your G-d, with happiness and goodness of heart" (ibid 6:20). Again, the juxtaposition of joy and goodheartedness appears to be the Rambam's source. Without helping the poor, one cannot experience true joy.
"Gladdening the heart of the poor, orphans, widows and strangers is the greatest and most splendid joy. One who does so resembles Hashem, Who revives the spirit of the lowly and the heart of the crushed" (Hilchos Megilla 2:17). Serving, and resembling, Hashem, the Source of joy (Divrei Hayamim I 16:27), yields the greatest possible happiness (See Purim, the Holiday of Giving).
III
"I have done all that You have commanded me" (Devarim 26:14) - this refers to the tithes eaten in Yerushalayim and the tithes given to the Levi and the poor (see Rashi). Rashi concludes: "I have rejoiced and have brought joy to others with it", referring to the aforementioned tithes respectively.
Rashi's formulation indicates that one must be joyous in order to make others happy. While others refer here to the Levi and the poor, earlier (14:26,27) the Torah also commands: "You shall rejoice, you and your household." This refers specifically to one's wife, without whom a man cannot enjoy true happiness (Yevamos 62b).
"'He shall gladden his wife'", as Onkelos translates. He who translates 'he shall be glad with his wife'" is mistaken" (Rashi, Devarim 24:5). The "mistaken" translation is none other than Yonasan ben Uziel. How do we justify his ungrammatical translation?
Perhaps Targum Yonasan is based on the linkage established by Rashi (26:14) himself, "I have rejoiced and have brought joy to others with it". In order to fulfill the literal sense of gladdening one's wife, one must first be glad with his wife. He should be overjoyed by his marriage, which yields Torah protection, peace, joy, blessing and goodness (Yevamos 62b). In fact, the Rambam (Hilchos Ishus 15:19) teaches that a married man may not be sad. His sadness will undoubtedly affect his wife and preclude his fulfillment of his obligation to gladden her. Targum Yonasan demands that a man be glad with his wife as a prerequisite to the literal requirement to gladden her.
True joy is achieved by serving Hashem with humility and love, and by giving and thereby resembling Hashem. The joy of marriage, the metaphor of loving Hashem (Rambam Hilchos Teshuva 10:3), is achieved by giving to and gladdening one's spouse as well. Indeed, a man and wife who merit it, Hashem dwells in their midst (Sota 17a).