Filterless optical networks (FONs) are a costeffective optical networking technology that replaces reconfigurable optical add-drop multiplexers, used in conventional, wavelength-switched optical networks (WSONs), by passive optical splitters and couplers. FONs follow the drop-and-waste transmission scheme, i.e., broadcast signals without filtering, which generates spectrum waste. Programmable filterless optical networks (PFONs) reduce this waste by equipping network nodes with programmable optical white box switches that support arbitrary interconnections of passive elements. Cost-efficient PFON solutions require optimal routing, modulation format and spectrum assignment (RMSA) to connection requests, as well as optimal design of the node architecture. This paper presents an optimization framework for PFONs. We formulate the RMSA problem in PFONs as a single-step integer linear program (ILP) that jointly minimizes the total spectrum and optical component usage. As RMSA is an NP-complete problem, we propose a two-step ILP formulation that addresses the RMSA sub-problems separately and seeks sub-optimal solutions to larger problem instances in acceptable time. Simulation results indicate a beneficial trade-off between component usage and spectrum consumption in proposed PFON solutions. They use up to 64% less spectrum than FONs, up to 84% fewer active switching elements than WSONs, and up to 81% fewer optical amplifiers at network nodes than FONs or WSONs.