This idiom originates from the Records of the Grand Historian (《史记》). Xiang Yu saw the Qin emperor's procession and said '彼可取而代也' — 'I could take his place.'
grammar
Often used as 'A取而代之' or 'A被B取而代之'. Can also stand alone when the replaced thing is clear from context.