The short answer is around the year 1620 in France and 1880 throughout Europe (Italy held out on modern castling).
In terms of how the pieces move and capturing en passant, the rules were codified by Ruy Lopez de Segura in the late 15th century. However, winning conditions differed at that time. Then, you could win by capturing all pieces save the king, making it possible to win with king+bishop, which is a draw in modern chess. Rules on castling were largely regional, and localities differed as to how the king moved. Some allowed one king move per game in an "L" shape, like a knight. This was inspired by chataraunga, the Indian precursor to chess. Some allowed castling in two moves. Some regions allowed a player to choose from several squares when castling. France, then England, adopted our modern version of castling in the 17th century. Italy held out, but eventually adopted the last of the rules we adhere to in modern chess.
For more, I highly recommend Murray's A History of Chess.