Leucaena leucocephala subsp. glabrata (giant leucaena) is a tree legume, whose foliage is used as a fodder for animals because of its high protein content. In spite of being a highly nutritious fodder, giant leucaena foliage has two undesirable secondary metabolites, mimosine and tannin. The amounts of mimosine and tannin in giant leucaena foliage are known to vary under different environmental conditions. Giant leucaena was grown under different salinity, pH and nitrogen availability conditions. It produced the highest amounts of mimosine at pH 6.0–7.0, whereas, variation in soil pH did not affect tannin concentrations. Salinity stress had negative effects on both mimosine and tannin concentrations, while nitrogen abundance promoted both mimosine and tannin production. Seven genes for mimosine and tannin metabolism were isolated from a transcriptome library of giant leucaena. These were mimosine synthase, mimosinase, chalcone synthase, flavanone 3β-hydroxylase, dihydroflavonol reductase, leucoanthocyanidin reductase, and anthocyanidin reductase. The highest level of mimosine synthase activity was observed in the absence of salt in the soils. Mimosine synthase activities had strong positive correlation with mimosine concentrations in the foliage (R2 = 0.78) whereas mimosinase expression did not appear to have a direct relationship with salt concentrations. The expression of mimosine synthase was significantly higher in the leucaena foliage under nitrogen abundant condition than in nitrogen deficiency conditions, while mimosinase expression was significantly higher under nitrogen deficiency condition than in nitrogen abundance conditions. Mimosine concentrations in the foliage were positively correlated with the expression levels of mimosine synthase but not mimosinase. Similarly, the concentrations of tannin were positively correlated with expression levels of dihydroflavonol reductase, leucoanthocyanidin reductase, and anthocyanidin reductase. Understanding of the environmental conditions that promote or inhibit transcription of the genes for mimosine and tannin biosynthesis should help to design environmental conditions that inhibit transcription of these genes, resulting in reduced levels of these compounds in the leucaena foliage.