Saudi Arabia can transition to a 100% renewable energy system by 2040 including the integration of the power, desalination and non-energetic industrial gas sectors. Single-axis tracking PV and battery storage contribute the highest to the final LCOE of the system. By 2050, single-axis tracking PV accounts for 79% of the total electricity generation. Battery storage accounts for 30% of the total electricity demand. Battery storage and desalination plants provide additional flexibility to the energy system. Through sensitivity analysis, it is found that decreasing the capex of desalination plants results in lower full load hours (FLH) and a decrease in battery storage output. This results in lower energy system costs. However, the SWRO capex has to be reduced by 50% to achieve a reduction of 1% in SWRO FLH and a 2.1% in the annualised energy system costs. This is because it is preferable to run the expensive SWRO plants in baseload operation for total energy system cost reasons. Flexibility to the energy system can be provided at a lower cost by solar PV and battery storage than by SWRO plants and water storage. Decreasing battery capex reduces the flexibility of desalination plants further, increases single-axis tracking PV capacities, decreases wind and CCGT capacities, and ultimately results in lower LCOE. These insights enable to establish the least cost pathway for Saudi Arabia to achieve net zero emissions by mid-century.