Chaggai was one of the last prophets; he was on the Beis Din of Ezra and was a member of the anshei kenesses hagdolah. Thus, he prophesied during a period after the destruction of the first Beis Hamikdash, when the people were in Bavel. He was a student of either Yechezkel or Baruch ben Neriah, and was a prophet in the days of Daryavesh, king of Persia. According to the Rambam, Chaggai lived until the destruction of the second Beis Hamikdash. Chaggai lived when Bnei Yisrael were in exile, but some had returned to Eretz Yisrael with the permission of Koresh (king of Persia) to build the second Beis Hamikdash. Indeed, Bnei Yisrael had laid the foundation stones for the Beis Hamikdash (and had celebrated accordingly at Sukkos time), until the renegade Bnei Yisrael (Kuthim) convinced Koresh to rescind his permission. Hashem told Chaggai to tell the people that the time had arrived to continue the rebuilding of the Beis Hamikdash (it had now been 70 years since the destruction of the first Beis Hamikdash).
In his Sefer Emes LeYaakov (Bo 12:2), Rav Yaakov Kamenetsky notes that according to the Mishnah in Shekalim (6:1) it would seem that the people knew where the original Aron was during the times of the second Temple – yet they did not retrieve and reinstall it. Similarly, the people kept their Aramaic language despite having returned to Eretz Yisrael to build the second Temple. Why? Rav Yaakov answers that the second Beis Hamikdash was only supposed to be a temporary stage to bring us up to a level whereby we could beckon in the final redemption and the third Temple. Thus, the people placed reminders (they kept their langauge and did not retreive the Aron) to ensure that they did not mistake this period for anything more than a conduit to the ultimate redemption. This is also why they did not appoint a king from Beis David during this era. With this principle, Rav Yaakov explains the oddity in the order of the books of the prophets. Why are the prophecies of Yechezkel (which concern the third Mikdash) put before those of Chagai (which refer to those of the second Mikdash)? For the third Mikdash gave the correct perspective to the second Mikdash.
Perek 1: Hashem had promised that the exile would last no longer than 70 years, but there was much debate as to when these 70 years commenced. Some of Bnei Yisrael had returned to Eretz Yisrael to begin building the second Beis Hamikdash (after Daryavesh had allowed its construction), but this had stopped due to the efforts of Bnei Yisrael’s enemies. Upon the completion of these 70 years (see Rashi 1:2 for the calculations), Hashem told Chaggai (then living in Yerushalayim) that the 70 years were over and it was time to start building the Beis Hamikdash (Radak 1:1). Chagai informed Bnei Yisrael that, contrary to popular belief, Hashem wanted the Beis Hamikdash to be rebuilt; how could they be building luxurious abodes for themselves while neglecting the construction of Hashem’s Beis Hamikdash? Chaggai highlighted five things that would happen if we would not rebuild the Beis Hamikdash; a low crop yield, non-satiating food, non-quenching drink, ineffective clothing, and unsuccessful commerce (Radak). Zerubavel and Yehoshua the Kohen Gadol related Bnei Yisrael’s unanimous verdict to establish the Beis Hamikdash, and Hashem responded “I am with you”. The building work began.
Perek 2: Hashem offered encouragement to Bnei Yisrael who recalled the splendor of the first Beis Hamikdash. Hashem promised to bestow His blessing on the nation through the second Beis Hamikdash (Metzudas David) even though there was a stark contrast between it and the first Mikdash. The blessing provided by the Beis Hamikdash does not depend on the beauty of its architecture, but rather on the observance of Torah and mitzvos by society (Abarbanel). Hashem would build the Beis Hamikdash to allow the nations to donate treasures to Hashem (Rashi). Chaggai related that the second Beis Hamikdash will exist for ten years longer than the first (Rashi’s second interpretation based on Bava Basra 3a), and Hashem will ensure that this period would be one of serenity. Chaggai inquired whether an item of food which had touched some stew, bread, or a dead body, would become impure; the Kohanim replied incorrectly that it would not (Rashi). Chagai criticized them, saying that just as the Kohanim would err regarding the laws of impurity, they were uneducated concerning the other laws of the Torah (Rashi). Chagai instructed the people to start learning the laws of the Beis Hamikdash to prepare for its rebuilding. Hashem had reduced the Bnei Yisrael’s produce as a reminder to serve Him (they did not take heed of this), but now their crops would flourish. Hashem promised that Bnei Yisrael would notice a remarkable difference in their crop’s yield once the Beis Hamikdash’s foundations were set. Zerubavel was chosen to lead the construction effort. Chagai prophesied that after the oppression of Paras, there will be further, but shorter, periods of suffering inflicted by Yavan. The tyranny of Yavan will end after the rebellion of the Chashmonaim (Rashi).Hashem would also promote Zerubavel’s stature.