Bacillus mojavensis D50, a biocontrol strain, is used to prevent and treat the fungal plant pathogen Botrytis cinerea. Bacillus mojavensis D50’s biofilms can affect its colonization; thus, the effects of different metal ions and culture conditions on biofilm formation were determined in this study. The results of medium optimization showed that Ca2+ had the best ability to promote biofilm formation. The optimal medium composition for the formation of biofilms contained tryptone (10 g/L), CaCl2 (5.14 g/L), and yeast extract (5.0 g/L), and the optimal fermentation conditions included pH 7, a temperature of 31.4 °C, and a culture time of 51.8 h. We found that the antifungal activity and abilities to form biofilms and colonize roots were improved after optimization. In addition, the levels of expression of the genes luxS, SinR, FlhA, and tasA were up-regulated by 37.56-, 2.87-, 12.46-, and 6.22-fold, respectively. The soil enzymatic activities which related biocontrol-related enzymes were the highest when the soil was treated by strain D50 after optimization. In vivo biocontrol assays indicated that the biocontrol effect of strain D50 after optimization was improved.