Driving EVs with optimized velocity profile would be an effective alternative to increasing EV energy efficiency and mitigating battery-related issues (short driving range, high cost and battery aging). Traffic light on the road poses a big challenge to existing velocity optimization methods because of its variable state and the dynamics of waiting vehicle numbers near the traffic light area. Besides, the vehicle following optimized velocity profile may often experience rear-end collision with frontal vehicle on the road. In this paper, for the first time, we propose a dynamic programming (DP)-based velocity optimization method which considers the vehicles waiting in traffic light area when optimizing velocity profiles. Also, we develop a collision avoidance system to avoid possible collisions and ensure driving safety when EVs follow optimized velocity profiles on the road. We collect real driving data on a 4.0 km long road section of US-25 highway and conduct extensive simulation studies to verify proposed systems. The velocity optimization simulation results from Matlab and Simulation for Urban MObility (SUMO) traffic simulator show that optimized driving pattern reduces energy consumption by 8.4% and 17.5% compared with real driving patterns without increasing trip time. Besides, we conduct a simulation study to evaluate the performance of collision avoidance system based on real driving patterns. The results show that proposed collision avoidance system helps EVs to avoid possible collisions with lower energy consumption compared with other existing collision avoidance systems.