This study addresses a three-echelon network design problem that determines the location and size of new warehouses, the removal of company-owned warehouses, the inventory levels of multiple products at the warehouses, and the assignment of suppliers as well as customers to warehouses over a multi-period planning horizon. A distinctive feature of our problem is that new warehouses operate with modular capacities that can be expanded or reduced over several periods, the latter not necessarily having to be consecutive. Moreover, in every period, the demand of a customer for a given product has to be satisfied by a single warehouse. The problem arises in the context of warehousing-as-a-service, a business scheme that offers flexible conditions for temporary capacity leasing. The associated fixed warehouse lease cost reflects economies of scale in the capacity size and the length of the lease contract. We develop a mixed-integer linear programming formulation and propose a matheuristic to solve this problem, which exploits the structure of the optimal solution of the linear relaxation to successively assign customers to open warehouses and fix other binary variables related to warehouse operation. Additional variable fixing rules are also developed, based on a scheme for managing inventories at warehouses and using the product quantities provided by suppliers. Numerical experiments with randomly generated large-sized instances reveal that the proposed matheuristic outperforms a general-purpose solver in 74% of the instances by identifying higher quality solutions in a substantially shorter computing time.