The Magen Abraham (Rav Abraham Gombiner, Poland, 1633-1683) writes that if a person was miraculously rescued from a life-threatening situation, it is proper for him to perform some service for the public. An early example of this practice is Yaakob Abinu, who, after being miraculously saved from the threats posed by Laban and Esav, and returning to his homeland, provided a number of valuable services for the benefit of the townspeople in the area where he settled. Specifically, he minted coins, and built marketplaces and bathhouses. The concept underlying this practice is the teaching of the Sefer Hasidim (Rabbenu Yehuda Ha’hasid of Regensburg, Germany, 1150-1217) that if one is miraculously rescued, he should assume that he earned a miracle because he has something important to contribute to the public. Therefore, it is proper to involve oneself in some way in helping the community. Some, for example, have the practice of printing a book of Torah literature.
Additionally, the Mishna Berura (Rav Yisrael Meir Kagan of Radin, 1839-1933) writes that the person should give charity, and proclaim just before he donates the money that this donation should take the place of a Korban Toda (thanksgiving offering), which he would be required to bring in the times of the Bet Ha’mikdash. He should also read the verses in the Torah that speak about this special sacrifice (Vayikra 7:11-15).
It is also customary to conduct a festive meal to celebrate the miracle and express gratitude to G-d, and this meal has the halachic status of a "Se’u’dat Misva" – a meal that fulfills a Misva.
Each year, on the anniversary of the event, it is proper for one to spend some in private reflecting on the miracle, rejoicing, and expressing his appreciation to G-d. It is also proper to have a festive meal on the anniversary of the miracle. Indeed, the Rambam (Rav Moshe Maimonides, Spain-Egypt, 1135-1204) writes that he was once miraculously saved from a sinking ship during a storm at sea, and he pledged at that time that he and his descendants would celebrate that day each year with a festive meal and charitable donations.
If a community was miraculously saved, then on the anniversary of the event, the somber Tahanunim prayers are omitted, and "Yehi Shem" is recited, instead. Our community, for example, adds an extra day following Shabuot when Tahanunim are omitted (the eighth day after Shabuot; Tahanunim are in any event omitted on the first seven days after Shabuot) to celebrate a great miracle that saved our ancestors in Aleppo. When one celebrates a private miracle, however, he recites Tahanunim on the anniversary of the event.
Summary: After one is miraculously saved from danger, it is proper to perform some service for the public, and to give charity in lieu of the thanksgiving offering that he would have to bring in the times of the Bet Ha’mikdash. It is also customary to conduct a festive meal. On the anniversary of the event each year, it is likewise proper to have a special meal, give charity, and spend time reflecting on the miracle and expressing profound gratitude to the Almighty. However, the Tahanunim prayers are recited as usual on the anniversary of one’s personal miracle.