This paper presents an intelligent PID control for stochastic systems with nonstationary nature. We optimally determine parameters of a PID controller through learning algorithm and propose an online PID control to compensate system errors possibly occurred in realtime implementations. A dynamic Bayesian network (DBN) model for system errors is additionally explored for making decision about whether an online control is carried out or not in practice. We apply our control approach to traffic control of Transmission Control Protocol (TCP) networks and demonstrate its superior performance comparing to a fixed PID from computer simulations.