Economic and environmental concerns have driven biofuel research in the last few decades. In order to this, biogas production is being encouraged on a worldwide scale to reduce carbon emissions and increase resource recovery from diversified wastes. The present contribution involves finding the best way to turn food waste and animal manure into biogas and its effective utilization in a dual‐fuel mode diesel engine. For the experimentation, a Taguchi approach was used to develop an L25 orthogonal array with three factors and five levels of parameters: cattle dung and food waste ratios, retention times, and digester temperatures. Using the response surface method (RSM), genetic algorithm (GA), and cuckoo search algorithm (CSA), the biogas yield was optimized and compared to get the best optimization technique. Based on the specific goals of the study, GA is the best combination of parameters for producing biogas. The optimal condition for producing biogas was a cattle dung and food waste ratio of 0:100 (wt/wt %) with a retention time of 15 days and a digester temperature of 40°C, and the corresponding value of the biogas yield was 551.633 mL/day. Experiments were done to confirm this prediction. This study also intends to determine the viability of ternary fuel blends (microalgae biodiesel, n‐butanol additive, and diesel) as a pilot fuel and biogas as a primary fuel by changing their mass flow rates (0.5, 1.0, and 1.5 kg/h) in the CI engine. The D70BD20Bu10 ternary fuel blend with 1.5 kg/h of biogas flow rate was found to be an optimum blend due to its improved performance and emission characteristics compared to other tested fuels. This fuel blending improves brake thermal efficiency (BTE) by 6.25% and reduces brake‐specific fuel consumption (BSFC) by 2.14%. NOx and smoke emissions were both reduced by 58.22% and 54.59%, respectively. However, HC and CO emissions were on the higher side compared to diesel.