In this work we address the problem of optimal design of reverse osmosis based water treatment systems. A superstructure optimization method is proposed to solve the problem, where the superstructure for a reverse osmosis is structurally enhanced with additional features. We formulate the problem as mixed-integer nonlinear program (MINLP) which is solved to yield optimal results. A case study on desalination is considered in this work, and the numerical results obtained using our approach are validated using a commercial simulation tool. We further extend the problem by considering the effects of degradation of membrane performance over time and solve it by representing the problem as a two-stage stochastic program.