The proper form of rejoicing is delighting in God and His mitzvot. The more the Jewish people rejoice in observance of the mitzvot, the more God will afford them joyous occasions.
“So I praised joy” (Ecclesiastes 8:15); this is a reference to the joy of a mitzva. “And of joy: What does it achieve?” (Ecclesiastes 2:2); this is a reference to joy that is not joy of a mitzva. This serves to teach you that the Divine Presence does not rest on an individual in an atmosphere of sadness, or of laziness, or of laughter, or of frivolity, or of idle conversation, or of idle chatter, but rather from an atmosphere imbued with the joy of a mitzva. As it is stated: “Now, bring me a musician. It was as the musician played, and the hand of the Lord was upon him” (II Kings 3:15). Rav Yehuda said: Likewise, one should be joyful over a matter of halakha.
Come and see how much the people of Israel cherish the mitzvot, as they incur expenses in order to observe the mitzvot and rejoice in them. The Holy One, blessed be He, declares: If you observe the mitzvot and rejoice in them, I will add joy to you, as it is stated: “The humble will increase their joy in the Lord” (Isaiah 29:19). (Shabbat 30b; Tanĥuma, Tazria)