Ezra 4 is chronologically muddled, evidence that the text accreted over time. Of course, we don't know how much of this actually happened. On the one hand, it's hard to see why these stories are here if there isn't some basis for them, on the other hand some of this doesn't seem very plausible. I'll try to sort out some of the complications.
In verses 1 and 2 Zerubabbel is not identified but he is the leader of the community, identified elsewhere in the Tanakh as being of the Davidic line and as the governor of Judah. The reference to Esahaddon king of Syria is to the story in 2 Kings 17, in which the Assyrians conquer Samaria, deport many of the inhabitants, and replace them with settlers. It is not impossible that some of them adopted the cult of Yahweh, or at least came to identify him with some other God to which they sacrificed. This sort of syncretism is common when cultures collide. (E.g. in the Caribbean Catholic saints became identified with Yoruba deities in Santeria.)Tthe leaders of Judah reject the offer of assistance in building the Temple, as Yahweh is "the God of Israel."
The story then gets interrupted, with interpolation of events that happened later. Verse 6 refers to the reign of Xerxes (485-465 BCE), so more than 50 years after the return in 538. Artaxerxes, in verse 7, is apparently the son of Xerxes (reigned 465-425 BCE), so close to 100 years later. The following verses were evidently originally in Aramaic, although the surviving texts are translations into Greek (Septuagint) and Hebrew (Masoretic). Verses 9-10 refer to historical events, recounted in Kings and Chronicles, in which Judah resisted paying tribute to previous empires, in an attempt to sway Artaxerxes. But again, this letter would have been written a century after the framing events, so the apparent causal link between verses 23 and 24 makes no sense -- it implies time travel into the past. In the next chapter, they resume work on the Temple in the reign of Darius, which began in 522 BCE, which actually makes sense, but obviously happened long before the events in verses 7 et seq which were supposed to have halted the work. So yeah, it's a total mess.
4 When the enemies of Judah and Benjamin heard that the exiles were building a temple for the Lord, the God of Israel, 2 they came to Zerubbabel and to the heads of the families and said, “Let us help you build because, like you, we seek your God and have been sacrificing to him since the time of Esarhaddon king of Assyria, who brought us here.”
3 But Zerubbabel, Joshua and the rest of the heads of the families of Israel answered, “You have no part with us in building a temple to our God. We alone will build it for the Lord, the God of Israel, as King Cyrus, the king of Persia, commanded us.”
4 Then the peoples around them set out to discourage the people of Judah and make them afraid to go on building.[a] 5 They bribed officials to work against them and frustrate their plans during the entire reign of Cyrus king of Persia and down to the reign of Darius king of Persia.
Later Opposition Under Xerxes and Artaxerxes
6 At the beginning of the reign of Xerxes,[b] they lodged an accusation against the people of Judah and Jerusalem.
7 And in the days of Artaxerxes king of Persia, Bishlam, Mithredath, Tabeel and the rest of his associates wrote a letter to Artaxerxes. The letter was written in Aramaic script and in the Aramaic language.[c][d]
8 Rehum the commanding officer and Shimshai the secretary wrote a letter against Jerusalem to Artaxerxes the king as follows:
9 Rehum the commanding officer and Shimshai the secretary, together with the rest of their associates—the judges, officials and administrators over the people from Persia, Uruk and Babylon, the Elamites of Susa, 10 and the other people whom the great and honorable Ashurbanipal deported and settled in the city of Samaria and elsewhere in Trans-Euphrates.
11 (This is a copy of the letter they sent him.)
To King Artaxerxes,
From your servants in Trans-Euphrates:
12 The king should know that the people who came up to us from you have gone to Jerusalem and are rebuilding that rebellious and wicked city. They are restoring the walls and repairing the foundations.
13 Furthermore, the king should know that if this city is built and its walls are restored, no more taxes, tribute or duty will be paid, and eventually the royal revenues will suffer.[e] 14 Now since we are under obligation to the palace and it is not proper for us to see the king dishonored, we are sending this message to inform the king, 15 so that a search may be made in the archives of your predecessors. In these records you will find that this city is a rebellious city, troublesome to kings and provinces, a place with a long history of sedition. That is why this city was destroyed. 16 We inform the king that if this city is built and its walls are restored, you will be left with nothing in Trans-Euphrates.
17 The king sent this reply:
To Rehum the commanding officer, Shimshai the secretary and the rest of their associates living in Samaria and elsewhere in Trans-Euphrates:
18 The letter you sent us has been read and translated in my presence. 19 I issued an order and a search was made, and it was found that this city has a long history of revolt against kings and has been a place of rebellion and sedition. 20 Jerusalem has had powerful kings ruling over the whole of Trans-Euphrates, and taxes, tribute and duty were paid to them. 21 Now issue an order to these men to stop work, so that this city will not be rebuilt until I so order. 22 Be careful not to neglect this matter. Why let this threat grow, to the detriment of the royal interests?
23 As soon as the copy of the letter of King Artaxerxes was read to Rehum and Shimshai the secretary and their associates, they went immediately to the Jews in Jerusalem and compelled them by force to stop.
24 Thus the work on the house of God in Jerusalem came to a standstill until the second year of the reign of Darius king of Persia.