I do a couple of things when I get off track:
1- forgive yourself - don't be disappointed that you got off track in the first place. life happens and plans go out the window when something unexpected comes up or boredom sets in. we miss our old ways because they were habit for a long time. we feel more comfortable with the familiar.
2- go back to basics - what worked for you in the beginning? what was your motivation? how did you battle bad days? try to mimic what you were doing when you were losing weight successfully. but LEARN what got you off track at the same time. maybe you restricted yourself too fast or stopped bad habits without rewarding yourself properly or by replacing them with new good habits. do a full recon of the situation.
3- keep it interesting - I get bored of the same food. the ONLY secret to what I've been able to do is to learn new fun recipes to make. i try new recipes as often as possible and keep those recipes in a box for when I don't have time to explore new ideas. i also learned to make bigger batches so i don't spend my life in the kitchen. same thing with exercise. Shake things up a bit even when you have a routine. Example: My bf and I go bowling on saturdays. Instead of getting one lane, we got two and did league style. We get a few minutes extra of practice rolls, and having a lane per person makes things go faster. We basically race bowled and finished our games in half the time.... so we stayed and played even more. Something that simple will keep us going back when things get boring.
3- keep up with posting on message boards - when giving other people advice, it shames you into following it yourself. Example: If I give someone advice on resisting a binge, how can I go and do it myself? I'd feel ashamed that I'm not even taking my own advice. It also is a way to brainstorm and keeps me on track.
hope that helped.