What is Judiasm's stance on joking, or in a broader sense being a jokester or lighthearted person? Is it seen as being a negative trait, or is being funny sometimes warranted in certain cases? If I am not mistaken in Gemara Avodah Zarah 46a the sages grant license and even consider it commendable to make fun of idolatry. I feel like excessive joking could be considered of a lack of Yiras shamayim though, and considered an serious aveira/bad mida.
I believe the answer is: It depends on the scenario, as you stated.
On one hand, there are many sources that speak about the negativity of merriment and the like. For example:
"Happy is the man who has not followed the counsel of the wicked, or taken the path of sinners, or joined the company of the insolent..." (with insolent coming from the Hebrew "לץ" - "Letz" which is related to joking around).
"Rabbi Akiva said: Merriment and frivolity accustom one to sexual licentiousness..."
"Greater is learning Torah than the priesthood and than royalty, for royalty is acquired by thirty stages, and the priesthood by twenty-four, but the Torah by forty-eight things...By a minimum of pleasure, By a minimum of frivolity..."
"On a similar note, the Gemara relates: Mar, son of Ravina, made a wedding feast for his son and he saw the Sages, who were excessively joyous. He brought a valuable cup worth four hundred zuz and broke it before them and they became sad. The Gemara also relates: Rav Ashi made a wedding feast for his son and he saw the Sages, who were excessively joyous. He brought a cup of extremely valuable white glass and broke it before them, and they became sad. Similarly, the Gemara relates: The Sages said to Rav Hamnuna Zuti at the wedding feast of Mar, son of Ravina: Let the Master sing for us. Since he believed that the merriment had become excessive, he said to them, singing: Woe unto us, for we shall die, woe unto us, for we shall die. They said to him: What shall we respond after you? What is the chorus of the song? He said to them, you should respond: Where is Torah and where is mitzva that protect us?"
And The New Israeli Commentary on Pirkei Avot states that because of these events, Rabbi Yochanan subsequently said the following:
In a similar vein, Rabbi Yoḥanan said in the name of Rabbi Shimon ben Yoḥai: One is forbidden to fill his mouth with mirth in this world, as long as we are in exile (ge’onim), as it is stated: “When the Lord returns the captivity of Zion we will be as dreamers” (Psalms 126:1). Only “then will our mouths fill with laughter and our lips with song” (Psalms 126:2). When will that joyous era arrive? When “they will say among nations, the Lord has done great things with these” (Psalms 126:2). They said about Reish Lakish that throughout his life he did not fill his mouth with laughter in this world once he heard this statement from his teacher, Rabbi Yoḥanan.
"אָמְרוּ עָלָיו עַל רֵישׁ לָקִישׁ, שֶׁמִּיָּמָיו לֹא מִלֵּא שְׂחוֹק פִּיו בָּעוֹלָם הַזֶּה, מְכִי שַׁמְעָהּ מֵרַבִּי יוֹחָנָן רַבֵּיהּ. קשא ודאי כל מילי דחסידותא דשמע ריש לקיש מן ר' יוחנן הוה מקיים, ומאי שנא האי דקא משמע לן עלה, ונראה לי בס"ד כי ריש לקיש היה טבעו בדחן, כמו בר קפרא, וכפי טבעו ומנהגו היה קשא עליו חסידות זו, ועם כל זה היה נזהר בה."
Translation: They said about Reish Lakish...And this is strange, for surely all of the sayings of piety that Reish Lakish heard from Rabbi Yochanan he would keep, and what difference is what he heard here and what he heard elsewhere? And it seems to me that Reish Lakish was naturally a jokester, like Bar Kapara, and according to his nature and his way of acting [in life], this type of piety was hard for him, and even so he was very careful about it.
And many more.
On the other hand, there are many sources that speak about the positivity of laughter and telling jokes:
"Rabbi Akiva said to him: But isn’t it already stated: “You shall destroy” (Deuteronomy 12:2)? This obviously includes rooting out all traces of idols. If so, what is the meaning when the verse states: “And you shall destroy their name out of that place”? This means that it is a mitzva to give it a nickname...Therefore, the verse states: “And you shall not bring an abomination into your house, and be accursed like it; you shall detest it, and you shall abhor it; for it is a proscribed item” (Deuteronomy 7:26). This verse clearly indicates that the nickname should be a negative one."
By giving idols negative, mocking nicknames, we fulfill a mitzvah.
"That explanation is like that which Rabba did. Before he began teaching halakha to the Sages, he would say something humorous and the Sages would be cheered..." (mentioned as well in Pesachim 117a)
And the Sages would be cheered - their hearts would open up because of the happiness (of the laughter).
Using laughter, Raba was able to bring his students to a state where they were more open to learning.
"The Gemara relates another story about the righteousness of common people. Rabbi Beroka Ḥoza’a was often found in the market of Bei Lefet, and Elijah the Prophet would often appear to him. Once Rabbi Beroka said to Elijah: Of all the people who come here, is there anyone in this market worthy of the World-to-Come?...In the meantime, two brothers came to the marketplace. Elijah said to Rabbi Beroka: These two also have a share in the World-to-Come. Rabbi Beroka went over to the men and said to them: What is your occupation? They said to him: We are jesters, and we cheer up the depressed. Alternatively, when we see two people who have a quarrel between them, we strive to make peace. It is said that for this behavior one enjoys the profits of his actions in this world, and yet his reward is not diminished in the World-to-Come."
The clear difference between the various sources is the quality and the quantity of the humor - this is also defined by the different terms used for humor and joking and joy (שחוק, ליצנות as opposed to בדיחות, שמחה). The quality - meaning the reasoning of the humor - should be for a good cause, such as helping students learn Torah, pulling people out of depression or helping people fulfill a mitzvah. And the quantity - setting limits, such as when the Emoraim broke priceless objects to stop the other rabbis from becoming too merry. That's why we find such sources as the following:
"The Gemara adds: Incidentally, this serves to teach you that the Divine Presence rests upon an individual neither from an atmosphere of sadness, nor from an atmosphere of laziness, nor from an atmosphere of laughter, nor from an atmosphere of frivolity, nor from an atmosphere of idle conversation, nor from an atmosphere of idle chatter, but rather from an atmosphere imbued with the joy of a mitzva.As it is stated with regard to Elisha, after he became angry at the king of Israel, his prophetic spirit left him until he requested: “But now bring me a minstrel; and it came to pass when the minstrel played, that the hand of the Lord came upon him” (II Kings 3:15)."
"וכל האמור לדוד מזמור שרתה שכינה עליו ואחר כך מזמור וכל האמור מזמור לדוד אמר שירה ואח"כ שרתה עליו שכינה ללמדך שאין השכינה שורה לא מתוך עצבות וכו' עד אלא מתוך שמחה שנא' ועתה קחו לי מנגן וכו' וכן להלכה וכן לחלום טוב ואסיקנא כי הא דרבא מקמי דלפתח בשמעתא הוה אמר מילתא דבדיחותא קמי רבנן לבדוחי לביהו והדר הוה יתיב באימתא ופתח בשמעתא וכל שכן תלמיד דלא ליתיב אלא באימתא"
Translation: "...And everything that says "to David a song", the Shechinah rested upon him and then he said a song, and everything that says "a song to David" - he said a song and then the Shechinah rested upon him, to teach you that the Shechinah doesn't present herself not out of an atmosphere of sadness etc but out of an atmosphere of happiness...and so is the Halachic ruling...and for this we see that Rava, before he taught Halacha to his students, he would tell a humorous thing, to cheer their hearts..."
"כי חזינן אינש דעציבא דעתיה מבדחינן כו'. דזכו בזה לעלמא דאתי כדאמרי' בפרק נ"ה כשאדם מצטער השכינה אומרת קלני מראשי כו' ע"ש:"
Translation: "When we saw people who were sad etc, they received for this [a part] to The World To Come...when a man is sad, the Shechinah proclaims "I am distressed about my head" etc, see there."
And so explains the Rambam in Hilchot De'ot, 2:7:
"Man shall not be frivolous and sarcastic, nor sad and pessimistic, but of good cheer...As a general rule of the matter he should follow the tendency of the middle-course of each and every disposition to the end that all of his tendencies will be firmly in the center, which is as Solomon said: "Balance well the track of thy foot, and let all thy ways be firmly right" (Prov. 4.26)."
Meaning: Don't over-do it.
"למשל, הגמרא אומרת (שבת ל, ב) 'דרבה מקמי דפתח להו לרבנן אמר מלתא דבדיחותא ובדחי רבנן, לבסוף יתיב באימתא ופתח בשמעתא' עד כאן לשון הגמרא, את המילתא דבדיחותא אמר מקדם כדי שיהיו בשמחה, כי אין השכינה שורה אלא מתוך שמחה, כמו שאמרה שם הגמרא, אבל התורה כפטיש יפוצץ סלע שמתחלק לכמה ניצוצות ולכמה טעמים ולדורנו מרמזת הגמרא עוד איזה דרך להרב והמלמד, שכדי לרפא את פצע ההתרחקות שנעשה בין התלמיד להמלמד, צריך המלמד להשתדל לקנות את לב התלמיד ולשוב ולקרבהו אליו, והשמחה היא אחת מעקרי האמצעים לקנותו, נפש הילד והנער אינה סובלת את העצבות, והמלמד אל יתראה בעיניו כרגזן ואיש מדון."
"For example, the Gemara says (Shabbat 30b) "Raba...a humorous thing..." until here the words of the Gemara, the humorous thing he said before everything, so that the Sages would be cheerful, for the Shechinah isn't present but out of a happy atmosphere, as the Gemara said...and to our generation the Gemara hints that this is another way for the rabbi and the student, that in order to cure the wound of the distance that happened between the student and teacher, the teacher must make many efforts to buy the heart of the student and to once again bring him closer to him, and happiness is one of the main ways to buy him, the soul of the child and the youth cannot handle the sadness, and the teacher must not appear before him in anger and fury."
In conclusion, humor is important because happiness is an important aspect of Avodat Hashem and humor helps bring about this state of happiness, but one shouldn't go overboard, and certainly not joke about more serious matters like arayot and stuff like that.