To decrease the greenhouse gas emissions of the maritime transport sector, synthetic fuels produced by combining biomass gasification and electrolytic hydrogen have been identified as relevant alternatives to fossil fuels. Dimethyl ether (DME) is a synthetic fuel that is suitable for direct use in commercial diesel ship engines. In this work, the production of DME via two different synthesis routes (one-and two-stage DME synthesis) from agricultural residues (wheat straw) or forestry residues (bamboo) and renewable electricity was investigated. In the four investigated plants, solid oxide electrolysis cells were used to produce hydrogen. The DME production systems were designed to operate using only wind and solar electricity. The energy and carbon efficiencies of the plants were evaluated by using detailed thermodynamic models. The performance of the plants was fed into an optimization model, and the levelized cost of fuel (LCOF) was minimized by optimizing the size and hourly operation of the DME production systems, including the DME synthesis plant, solid oxide electrolyzer, hydrogen storage, solar and wind power production, and batteries. The results show that the systems using a two-stage synthesis achieve higher carbon and energy efficiencies than one-stage systems. However, the lowest LCOF of 115 €/MW h was reached by the plant using bamboo and a one-stage synthesis. This system had a hydrogen and electricity consumption of up to 45% lower than the alternative systems, leading to lower cost of the power supply, storage, and electrolysis units. A sensitivity analysis showed that the LCOF of the plants is highly sensitive to variations in the cost of electrolyzers, biomass, and the DME synthesis plant.