In this paper, optimal switching and control approaches are investigated for switched systems with infinite-horizon cost func-tions and unknown continuous-time subsystems. At first, for switched systems with autonomous subsystems, the optimal solution based on the finite-horizon HJB equation is proposed and a data-driven optimal switching algorithm is designed. Then, for the switched systems with subsystem inputs, a data-driven optimal control approach based on the finite-horizon HJB equation is proposed. The data-driven approaches approximate the optimal solutions online by means of the system state data instead of the subsystem models. Moreover, the convergence of the two approaches is analyzed. Finally, the validity of the two approaches is demonstrated by simulation examples.