Plug-in hybrid electric vehicles are a midterm solution to reduce the transportation sector's dependency on oil. However, if implemented in a large scale without control, peak load increases significantly and the grid may be overloaded. Two algorithms to address this problem are proposed and analyzed. Both are based on a forecast of future electricity prices and use dynamic programming to find the economically optimal solution for the vehicle owner. The first optimizes the charging time and energy flows. It reduces daily electricity cost substantially without increasing battery degradation. The latter also takes into account vehicle to grid support as a means of generating additional profits by participating in ancillary service markets. Constraints caused by vehicle utilization as well as technical limitations are taken into account. An analysis, based on data of the California independent system operator, indicates that smart charge timing reduces daily electricity costs for driving from $0.43 to $0.2. Provision of regulating power substantially improves plug-in hybrid electric vehicle economics and the daily profits amount to $1.71, including the cost of driving.