(Note: dates and periods are in many cases approximate and/or conventional)
The period of the First Temple ended in 586 BCE when the Babylonian king Nebuchadnezzar captured Jerusalem, destroyed the Temple of Solomon, and deported the elite of the population to Babylon (the "Babylonian exile"). In 539 BCE Babylon itself fell to the Persian conqueror Cyrus, and in 538 BCE the exiles were permitted to return to Yehud medinata, as the Persian province of Judah was known. The Temple is commonly said to have been rebuilt in the period 520-515 BCE, but it seems probable that this is an artificial date chosen so that 70 years could be said to have passed between the destruction and the rebuilding, fulfilling a prophecy of Jeremiah.
The end of the Persian period is conventionally dated from Alexander the Great's conquest of the Mediterranean coast in 333/332 BCE. His empire disintegrated after his death, and Judea, including Jerusalem, fell to the Ptolemies, the descendants of one of Alexander's generals who ruled Egypt. In 200 BCE Israel and Yehud were captured by the Seleucids, the descendants of another Greek general ruling Syria. Around 167 BCE, for reasons that remain obscure, the Seleucid king Antiochus IV Epiphanes attempted to suppress Jewish worship; this provoked a Jewish revolt (the Maccabean Revolt) that eventually led to the effective end of Greek control over Jerusalem.
Hasmonean Judea was a client kingdom of the Romans, and in the 1st century BCE the Romans first replaced them with their protege Herod the Great, and, on Herod's death in 6 CE, made Judea a province under Rome's direct rule. Heavy taxes under the Romans and insensitivity towards the Jewish religion led to revolt (the First Jewish-Roman War, 66-73 CE), and in 70 CE the Roman general (and later emperor) Titus captured Jerusalem and destroyed the Temple, bringing an end to the Second Temple period.
The Jewish exiles in Babylon were not slaves or prisoners, nor were they badly treated, and when the Persians gave permission for them to return to Jerusalem the majority elected to remain where they were. They and their descendants formed the diaspora, a large community of Jews living outside Judea, and the 1st century CE historian Josephus reported that there were more Jews in Syria (meaning the Seleucid empire) than in any other land. There was also significant Egyptian diaspora, although the Jews of Egypt were immigrants, not deportees, "...attracted by Hellenistic culture, eager to win the respect of the Greeks and to adapt to their ways" (John J. Collins, "Between Athens and Jerusalem). The Egyptian diaspora was slow to develop, but in the Hellenistic period it came to outstrip the Babylonian community in importance. In addition to these major centres there were Jewish communities throughout the Hellenistic and subsequently the Roman world, from North Africa to Asia Minor and Greece and in Rome itself.
The separation between Jews of Jerusalem and those of Samaria was a long and protracted process. For most of the Second Temple period Samaria was larger, richer, and more populous than Judea - down to about 164 BCE there were probably more Samaritans than Judeans living in Palestine. They had their own temple on Mount Gerizim near Shechem and regarded themselves as the only true Israel, the remnant left behind when Israel was deceived by the wicked priest Eli to leave Gerizim and worship at Jerusalem. Second Temple Judeans regarded them as foreign converts and the offspring of mixed marriages, and therefore of impure blood. Relations between the two communities were often strained, but the definitive break dates from the destruction of the Gerizim temple and of Shechem by a Hasmonean king in the late 2nd century BCE; before that the Samaritans seem to have regarded themselves as part of the wider Jewish community, but afterwards they denounced the Jerusalem temple as completely unacceptable to God.
In recent decades it has become increasingly common among scholars to assume that much of the Hebrew bible was assembled, revised and edited in the 5th century BCE to reflect the realities and challenges of the Persian era. The returnees had a particular interest in the history of Israel: the written Torah (the books of Genesis, Exodus, Leviticus, Numbers and Deuteronomy), for example, may have existed in various forms during the Monarchy (the period of the kingdoms of Israel and Judah), but it was in the Second Temple that it was edited and revised into something like its current form, and the Chronicles, a new history written at this time, reflects the concerns of the Persian Yehud in its almost-exclusive focus on Judah and the Temple.