This paper considers a challenging problem: to simultaneously optimize the cost and the quality of service in opaque wavelength division multiplexing (WDM) networks. An optimization problem is proposed that takes the information including network topology, traffic between end nodes, and the target level of congestion at each link/ node in WDM networks. The outputs of this problem include routing, link channel capacities, and the optimum number of switch ports locally added/dropped at all switch nodes. The total network cost is reduced to maintain a minimum congestion level on all links, which provides an efficient trade-off solution for the network design problem. The optimal information is utilized for dynamic traffic in WDM networks, which is shown to achieve the desired performance with the guaranteed quality of service in different networks. It was found that for an average link blocking probability equal to 0.015, the proposed model achieves a net channel gain in terms of wavelength channels ( 𝛾 w ) equal to 35.72 % , 39.09 % , and 36.93 % compared to shortest path first routing and 𝛾 w equal to 29.41 % , 37.35 % , and 27.47 % compared to alternate routing in three different networks.