A. The Background of the custom:
The Piyut of Shalom Aleichem was established by the Kabalists, the students of the Arizal and is recorded in the Poskim to be said on Friday night upon arrival home from Shul. It is recited in light of the Talmudic statement that on Shabbos every person is escorted by two angels upon returning from Shul, one good and one evil. There are various dialects of this Piyut. We recite the dialect printed by Admur in his Siddur. The Piyut of Tzeischem Leshalom is not bidding farewell to the angels, as the angels remain the entire Shabbos, and rather it is to bless them when they eventually leave after Shabbos.
B. The details of the custom:
Upon arriving home one is to recite Shalom Aleichem and Eishes Chayil. It is to be said immediately upon arriving home, even if one does not plan to start the meal right away. It is to be said equally by every man and woman. It is to be said standing. Each Piyut is said three times in order to strengthen the matter.
Yom Tov that coincides with Shabbos: When Yom Tov or Chol Hamoed falls on Friday evening, and Shabbos Chol Hamoed, some are accustomed not to recite Shalom Aleichim. Others are accustomed to recite it as usual. Practically, the Chabad custom is to recite it in an undertone.
 Siddur Admur; Sefer Tikkunei Shabbos ; Siddur Shlah; Siddur Arizal of Rav Yaakov Kopel; Tosefes Shabbos 262; Machazik Bracha 262/2; Shulchan Hatahor 262/3; Machatzis Hashekel 262; Kaf Hachaim 262/16; Piskeiy Teshuvos 271/2 footnote 18; See other opinions in footnotes below
 Shabbos 119b
 See Likkutei Maharich; Piskeiy Teshuvos 271 footnote 18
 See Darkei Moshe 262; M”A 262/1
 Machazik Bracha 262/2; Machatzis Hashekel 262; Mishmeres Shalom 27/8; Kaf Hachaim 262/16; See Shulchan Hatahor 262/3; See Tosefes Shabbos 262 that some omit this stanza due to the above issue that in truth the angels remain the entire Shabbos; See Likkutei Maharich for a different Nussach that avoids this problem; Piskeiy Teshuvos 271/2 footnote 18
 Siddur Admur; Sefer Tikkunei Shabbos ; Siddur Shlah; Siddur Arizal of Rav Yaakov Kopel; See Poskim ibid
Other customs: Some question the recital of this Piyut today when we are no longer on a level where we have angels escort us and it is similar to “Hiskabdu Michubadim…“ which we also no longer recite due to this reason. [Chasam Sofer brought in Chaver Ben Chaim; Hagahos Rebbe Rashab on Siddur, printed in Siddur Raskin footnote 97; See Mor Uketzia 3/1] Accordingly, it is said that some Gedolei Yisrael did not recite this Piyut at all. [Chasam Sofer ibid; Tzemach Tzedek and Ziknei Chassidim, brought in Siddur Raskin ibid] The Chofetz Chaim would not even sing the hymn of Shalom Aleichem when he had guests in order to start the meal right away. [Piskeiy Teshuvos 271 footnote 36] Nevertheless the custom is to say it, as on Shabbos even the Reshaim have good angels escort him, as explicitly written in the Gemara. [Piskeiy Teshuvos 3 footnote 3 and 271 footnote 8]
 Kaf Hachaim 271/2
 Tikkunei Shabbos ibid
 Siddur Keser Nehora, and so is the custom
 Siddur Admur
The reason: This is similar to the Talmudic statement in Menachos 65a that “Magal Zeh” was said three times. [Likkutei Maharich]
 Alef Hamagen 583/1; Divrei Torah 9/72
 The reason: As it is shameful to Yom Tov to only mention a Piyut greeting Shabbos. [ibid]
 Mateh Efraim 583/1
 Sefer Haminhagim p. 118 [English]; Hayom Yom 19th Nissan and 17th Tishreiy; See Otzer Minhagei Chabad Nissan p. 142; See Hisvadyus 1986 3/187; Piskeiy Teshuvos 271/2
Original Chabad custom: In the earlier prints of Hayom Yom p. 46 it stated that one does not say Shalom Aleichem or Eishes Chayil at all on Shabbos Yom Tov or Shabbos Chol Hamoed. This was based on an explicit directive of the Rebbe Rayatz that one is not to say it and that so was the custom of the Rebbe Rashab and the Rebbe Maharash, although there were some years in which they said it. [Reshimos 4/12 and 22; 38/9]