In describing some of the details relating to one who brings a goat for a Korban Shelamim, a peace offering, the Torah states "כל חלב לה'," indicating that all the choice parts of the animal are for Hashem (ויקרא ג':ט"ז). The Sifra (פ' ויקרא פרק כ' הלכה ה'), analyzing this Posuk (שם), points out that this phrase seems to be superfluous, presumably because the Torah already mentions exactly which parts of the animal had to be sacrificed (שם פסוקים י"ד-ט"ו). The Sifra (שם) thus explains that the intent of this phrase is to teach that the choice parts of the animal specified with regards to the Korban Shelamim must also be sacrificed in the case of other offerings as well, even where the Torah does not precisely identify that those parts must be sacrificed. In other words, the choice parts enumerated here must be offered on the Mizbeiach even when bringing sacrifices concerning which the Torah does not specifically require that this be done, and the Sifra (שם) gives examples of such offerings; this probably is what the Torah means by saying "כל חלב...," "all the choice parts..." (ויקרא שם). It should be noted, though, that according to one opinion in the Gemara in Zevachim (דף ל"ז.), as cited by the Raavad in his commentary on the Sifra (פירוש הראב"ד שם), this idea regarding other sacrifices is derived from a different source entirely. Whatever the exact source, however, the Rambam (פרק א' מהל' מעשה הקרבנות הלכה י"ח) rules simply that all these inner parts of the animal, known as אימורין, are burnt on the Mizbeiach when offering any type of the Korbanos mentioned there; he later adds (שם פרק ה' הלכה י"ח) that the אימורין from all Korbanos are burnt on the Mizbeiach after the sprinkling of the animal's blood.
Although the Posuk in our Parsha (שם) which says "כל חלב לה'," "all the choice parts are for Hashem," is clearly presenting a detail which is relevant to the Halachos of Korbanos, as explained above, the Rambam (פרק ז' מהל' איסורי המזבח הלכה י"א) takes the phrase a step further and extrapolates from here an idea that is relevant to all Mitzvos. The Rambam (שם) writes that one who wants to earn merit for himself should bring offerings to Hashem only from the very best quality of whatever it is that he is bringing, noting that the Torah earlier (בראשית ד':ד') states that Hevel offered the very best of his flock to Hashem, and that his offering was accepted by Hashem. He then adds (שם) that this same principle applies to everything which is done for the sake of Hashem, meaning that anything dedicated to Hashem ought to be of the most beautiful and best quality. Therefore, for example, if one builds a Shul, it should be more beautiful than his own dwelling place, if one feeds the hungry, he should give from the best and tastiest of whatever he has at his table, if one provides clothes for a poor person who needs them, he should give from the finest of his garments, and if one dedicates anything to the Beis HaMikdash (as a dedication known as "Hekdesh"), he should give from the best of his property. The Rambam concludes this lesson (שם) by citing the phrase "כל חלב לה'" from the Posuk in our Parsha (ויקרא שם), which he clearly understands to signify that one should always give his best when serving Hashem. The Kessef Mishneh (להלכה ח' שם) implies that this is the Rambam's own interpretation, which he thinks is proper, and it is codified in the Shulchan Aruch (יורה דעה סימן רמ"ח סעיף ח'), and quoted as well by the Kitzur Shulchan Aruch (סימן ל"ד סעיף ה') and the Aruch HaShulchan (יו"ד שם סעיף ט"ו), who adds that one should engage in all these activities with generosity and with a glad heart.
In the particular case of building a Shul, the Gemara in Shabbos (דף י"א.) states that a Shul should be the tallest, and hence the most prominent and outstanding, edifice in the entire town, as hinted at by a Posuk in Ezra (ט':ו'); a similar idea is found in the Tosefta in Megillah (פרק ג' הלכה י"ד), based on a Posuk in Mishlei (א':כ"א). This view is codified by the Rambam (פרק י"א מהל' תפילה הלכה ב') and by the Shulchan Aruch (אורח חיים סימן ק"נ סעיף ב'); although the Ateres Zekeinim (שם בד"ה אין) and the Magen Avraham (שם ס"ק ב') explain why this ruling may not be in effect to the same extent today, when Jews live among non-Jews, the Mishnah Berurah (שם ס"ק ד') and the Kaf HaChaim (שם אות י"ח) write that one should be careful to observe this to the extent that it is possible even today, as indicated as well by the Shaarei Teshuvah (שם ס"ק ג'). The Gemara later in Shabbos (דף ק"ב:) indicates that there should be no display of poverty when it comes to service of Hashem; the same idea, with different specific applications, is found as well in the Gemara in Menachos (דף פ"ט., ועיין שם בתוד"ה אין), and in Tamid (דף כ"ט.), and elsewhere. It should be noted, though, that one should not spend money frivolously and ostentatiously even for something intended to serve Hashem; the Gemara in Yoma (דף ל"ט., ועיין שם ברש"י ד"ה התורה), for example, indicates that one should not spend money on a fancier or more extravagant item if it is not really necessary. Commenting on the Gemara in Rosh Hashanah (דף כ"ז.) which indicates the same thing, the Maharam Ibn Chaviv (ספר יום תרועה על מס' ראש השנה שם בד"ה גמרא) notes that there stems to be a contradiction, as indeed is implied by the aforementioned Gemara in Menachos (שם), between this notion that one should not spend excessively even for a Mitzvah and the idea that one should not demonstrate any poverty when it comes to service of Hashem; he suggests that it is simply up to the Chachomim to determine which type of Mitzvos one should spend freely on, and which types one should avoid spending too much on. This idea is quoted as well by the Yad Malachi (כללי הגמרא, כללי הה"א, אות רכ"ט), and by the Tiferes Yisrael, commenting on a Mishnah in Tamid (פרק ה' משנה ה' אות כ"ז), who suggest that each situation must be dealt with individually (ועיין עוד בתפארת ישראל על המשנה בשקלים פרק ח' משנה ה' אות ל"ד ובבועז שם אות ג').
The Gemara still later in Shabbos (דף קל"ג:) extrapolates from the Torah's famous phrase "זה ק-לי ואנוהו," "this is my G-d and I will glorify Him" (שמות ט"ו:ב'), that one should try to beautify the Mitzvos which he performs before Hashem, such as by having a beautiful Sukkah, a beautiful Lulav, a beautiful Shofar, beautiful Tzitzis, and a beautiful Sefer Torah. The same idea is found in the Mechilta there (פ' בשלח-השירה פרשה ג' בד"ה זה), and in the Yerushalmi in Peiah (פרק א' הלכה א', דף ב:), where beautiful Tefillin are also mentioned, as well as in the Beraisa in Maseches Soferim (פרק ג' הלכה י"ג), where having beautiful Mezuzos is also included. The Sdei Chemed (כללים, מערכת זיי"ן כלל י"ב) discusses at some length the question of whether this idea of beautifying the Mitzvos, meaning, to perform what is known as a Hiddur Mitzvah, is mandated by the Torah or is required only MideRabbanan. He writes that it appears from Tosafos in Menachos (דף מ"א: בד"ה אין), as well as in Shabbos (דף ק"ד: בד"ה אמר), as explained by the Maharsha there (חדושי הלכות שם בד"ה בד"ה), and in Sukkah (דף כ"ט: בד"ה לולב), that Hiddur Mitzvah is required only MideRabbanan; he also cites the Ritva in Sukkah (חדושי הריטב"א לדף י"א: שם בד"ה ואי) and the Rosh in Bava Kamma (פרק א' סימן ז'), among others, as holding this way. This also seems to be the position of the Meiri in Shabbos (בית הבחירה לדף קל"ג: שם בד"ה לעולם), as well as the Maharashal in his Yam Shel Shlomo in Bava Kamma (פרק א' סימן כ"ד), as understood by the Chasam Sofer (שו"ת חתם סופר חלק או"ח סימן קפ"ד), and this is the view accepted by the Beis Yosef, commenting on the Tur (או"ח סימן תרנ"ו בד"ה קנה).
The Sdei Chemed (שם) also writes, though, that it appears from Rashi in Sukkah (שם בד"ה יבש), as well as from the Sefer Chassidim (סימן תתע"ח, תתע"ט), that the concept of Hiddur Mitzvah is MideOraisa, and he notes that according to the Shaagas Aryeh (שו"ת שאגת אריה סימן נ'), this may also be the view of the Rambam (פרק ב' מהל' מילה הלכה ד'). This also seems to be the position of the Raavad, in his commentary on the Baal Hamaor in Sukkah (השגות הראב"ד על ספר המאור הקטן שם, דף ז. בדפי הרי"ף בסוף ד"ה אמר), and it is clearly the view of the Chidushei Anshei Sheim on the Rif in Berachos (דף ל"ח. בדפי הרי"ף שם אות ב'), as well as of the Netziv, in his commentary on the Sheiltos entitled Haamek She'eilah (פ' שלח, שאילתא קכ"ו סוף אות ה'). This may also be the view of the Chasam Sofer, in his Chidushim on the aforementioned Gemara in Sukkah (פרק לולב הגזול שם בד"ה והיבש, נדפס בסוף שו"ת חתם סופר חלק ו'), and it is the view of his Talmid, the Maharam Schick (שו"ת מהר"ם שיק חלק יו"ד סימן רנ"ה). The Sdei Chemed (שם) concludes that it is possible to hold that the notion of Hiddur Mitzvah is indeed MideOraisa, but specifics like how much to spend in order to beautify a Mitzvah are determined by the Rabbanan; a similar suggestion is advanced by the Maharam Ibn Chaviv (ספר כפות תמרים על מס' סוכה שם בד"ה ומ"ש התוס'), who suggests that while the principle of Hiddur Mitzvah is MideOraisa, it was left up to the Rabbanan to decide how strict to be with this requirement regarding different Mitzvos.
The Gemara in Bava Kamma (דף ט:), as interpreted by Rashi (שם בד"ה בהידור) and, as pointed out by the Vilna Gaon (הגהות הגר"א שם אות א'), many others, indicates that if one has a choice between two items which are suitable for a Mitzvah, and one is clearly more beautiful than the other, one should spend as much as a third more money in order to buy the better one; this explanation is also presented by the Nimukei Yosef there (דף ד. בדפי הרי"ף בד"ה גרסי'), and, apparently, by the Meiri there (בית הבחירה שם בד"ה לעולם) as well. The aforementioned Beis Yosef (או"ח שם) explains that according to this view, though, if one has already purchased his item for the Mitzvah and then comes across a more beautiful one, he is not required to now purchase the more beautiful one for the sake of the Hiddur Mitzvah, even if he can get it inexpensively. According to the Rosh in Bava Kamma cited above (שם), as well as according to the Semag (מצות עשה מ"ד), however, if the original item considered for use for the Mitzvah meets only the bare minimum standards for the Mitzvah, one must spend up to a third more money if he comes across a better item even if he has already purchased the first one; the Rosh in Sukkah (פרק ג' סימן י"ב) says in general that even after one has purchased an item for a Mitzvah, he must spend up to a third more to obtain a better one if he comes across it, and the Taz (או"ח שם ס"ק א') clarifies the exact position of the Rosh, based on his two statements (שם ושם). As pointed out by the Vilna Gaon (ביאור הגר"א לאו"ח שם בד"ה ויש), this latter view is the one presented in the Yerushalmi in Peiah quoted above (שם, ועיין שם במראה הפנים בד"ה למצות), and it is codified by the Tur (שם); the Mishnah Berurah in his Shaar HaTziyun (שם אות ב') argues that Rashi (שם) may actually agree to this too. It should be noted that according to Tosafos in Bava Kamma (שם בד"ה עד), the "one-third" relates not to the amount of money one must spend on the item, but to the size (or presumably, the relative beauty) of the item, meaning that if one finds, for example, a very small and minimally acceptable Esrog, and then finds one which is one-third bigger, he should buy the bigger one; the Magen Avraham (שם ס"ק ה') says something similar, and the Maharsha in Bava Kamma (חדושי אגדות שם בד"ה אילימא) gives a reason for this which applies at least to the Mitzvah of Arba Minim on Sukkos.
The Shulchan Aruch (או"ח שם סעיף א') actually quotes both the view that if one bought a minimally acceptable item and then found a better one he must spend up to a third more money to obtain the better one, and the view that if one has a choice between two items to buy for a Mitzvah he should spend up to a third more to get the better one; the Kaf HaChaim (שם אות ט') writes that we should follow the stricter side of each view, which he explains. The Magen Avraham (שם ס"ק ב') notes that although the specific discussion here is about an Esrog, it applies to other Mitzvos as well, and the Mishnah Berurah (שם ס"ק ב') and the Kaf HaChaim (שם אות י') agree. The Mishnah Berurah notes in his Biur Halacha (שם בד"ה בצמצום), as do others, that even according to those who hold that if one already bought the item but then finds a better one he must spend up to a third more in order to obtain the better one, this requirement exists only one time regarding a particular Mitzvah, and one thus does not have to keep spending more and more money if he keeps coming across better items. The Magen Avraham (שם ס"ק ד') points out that this whole idea of spending a third more money on a better item after having bought an inferior one applies only if the seller will take back the first item and exchange it, but if not, he does not have to buy the better item; the Mishnah Berurah in his Shaar HaTziyun (שם) concurs, as does the Kaf HaChaim (שם אות ט"ו), although he cites others who disagree. The Gemara in Bava Kamma (שם) concludes, as explained by Rashi (שם בד"ה מכאן), that if one spends even more than the required one-third extra in order to beautify a Mitzvah, Hashem will reward him in this world accordingly; Tosafos (שם בד"ה משל) notes that this conduct will bring a reward in Olam HaBo as well, and Rabbeinu Chananel (שם) adds that one should thus use any unexpected income for the purpose of performing a Hiddur Mitzvah.